mirror of https://git.tuxpa.in/a/code-server.git
17 lines
524 B
TypeScript
17 lines
524 B
TypeScript
import proxyServer from "http-proxy"
|
|
import { HttpCode } from "../common/http"
|
|
|
|
export const proxy = proxyServer.createProxyServer({})
|
|
|
|
proxy.on("error", (error, _, res) => {
|
|
res.writeHead(HttpCode.ServerError)
|
|
res.end(error.message)
|
|
})
|
|
|
|
// Intercept the response to rewrite absolute redirects against the base path.
|
|
proxy.on("proxyRes", (res, req) => {
|
|
if (res.headers.location && res.headers.location.startsWith("/") && (req as any).base) {
|
|
res.headers.location = (req as any).base + res.headers.location
|
|
}
|
|
})
|