Skip to content

Commit eac7040

Browse files
committed
wip
1 parent b83d6ca commit eac7040

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/node/proxy.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { HttpCode } from "../common/http"
44
export const proxy = proxyServer.createProxyServer({})
55

66
proxy.on("error", (error, _, res) => {
7+
console.log("yoooo")
78
res.writeHead(HttpCode.ServerError)
89
res.end(error.message)
910
})

test/unit/proxy.test.ts

+32-1
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ describe("proxy (standalone)", () => {
157157

158158
beforeAll(async () => {
159159
await testServer.listen((req, res) => {
160+
proxyServer.web(req, res, { target: `http://localhost:${testServer.port()}` })
160161
expressServer(req, res)
161162
})
162-
await proxyServer.listen(testServer.port())
163163
})
164164

165165
afterAll(async () => {
@@ -190,3 +190,34 @@ describe("proxy (standalone)", () => {
190190
expect(resp.status).toBe(500)
191191
})
192192
})
193+
194+
describe("test dummy", () => {
195+
it("should return a 200", async () => {
196+
const testServer = new httpserver.HttpServer()
197+
198+
await testServer.listen(function (req, res) {
199+
proxy.web(req, res, {
200+
target: `http://localhost:${testServer.port()}`,
201+
})
202+
203+
if (req.url === "/error") {
204+
res.statusCode = 500
205+
res.end("ERROR")
206+
return
207+
}
208+
209+
res.writeHead(200, { "Content-Type": "text/plain" })
210+
res.write("nice joe")
211+
res.end()
212+
})
213+
214+
const resp = await testServer.fetch(`/wsup`)
215+
expect(resp.status).toBe(200)
216+
expect(resp.statusText).toBe("OK")
217+
218+
const errorResp = await testServer.fetch(`/error`)
219+
expect(errorResp.status).toBe(500)
220+
221+
await testServer.close()
222+
})
223+
})

0 commit comments

Comments
 (0)