|
| 1 | +import * as integration from "./integration" |
| 2 | +import * as httpserver from "./httpserver" |
| 3 | +import * as express from "express" |
| 4 | +import * as assert from "assert" |
| 5 | + |
| 6 | +describe("proxy", () => { |
| 7 | + let codeServer: httpserver.HttpServer | undefined |
| 8 | + let nhooyrDevServer = new httpserver.HttpServer() |
| 9 | + let proxyPath: string |
| 10 | + |
| 11 | + before(async () => { |
| 12 | + const e = express.default() |
| 13 | + await nhooyrDevServer.listen(e) |
| 14 | + e.get("/wsup", (req, res) => { |
| 15 | + res.json("asher is the best") |
| 16 | + }) |
| 17 | + proxyPath = `/proxy/${nhooyrDevServer.port()}/wsup` |
| 18 | + e.get(proxyPath, (req, res) => { |
| 19 | + res.json("joe is the best") |
| 20 | + }) |
| 21 | + }) |
| 22 | + |
| 23 | + after(async () => { |
| 24 | + await nhooyrDevServer.close() |
| 25 | + }) |
| 26 | + |
| 27 | + afterEach(async () => { |
| 28 | + if (codeServer) { |
| 29 | + await codeServer.close() |
| 30 | + codeServer = undefined |
| 31 | + } |
| 32 | + }) |
| 33 | + |
| 34 | + it("should rewrite the base path", async () => { |
| 35 | + ;[,, codeServer,] = await integration.setup(["--auth=none"], "") |
| 36 | + const resp = await codeServer.fetch(proxyPath) |
| 37 | + assert.equal(resp.status, 200) |
| 38 | + assert.equal(await resp.json(), "asher is the best") |
| 39 | + }) |
| 40 | + |
| 41 | + it("should not rewrite the base path", async () => { |
| 42 | + ;[,,codeServer,] = await integration.setup(["--auth=none", "--proxy-path-passthrough=true"], "") |
| 43 | + const resp = await codeServer.fetch(proxyPath) |
| 44 | + assert.equal(resp.status, 200) |
| 45 | + assert.equal(await resp.json(), "joe is the best") |
| 46 | + }) |
| 47 | +}) |
0 commit comments