Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/src/node/proxy.ts

18 lines
606 B
TypeScript
Raw Normal View History

2020-10-21 01:05:58 +02:00
import proxyServer from "http-proxy"
import { HttpCode } from "../common/http"
2020-10-21 01:05:58 +02:00
export const proxy = proxyServer.createProxyServer({})
2020-10-21 01:05:58 +02:00
proxy.on("error", (error, _, res) => {
res.writeHead(HttpCode.ServerError)
res.end(error.message)
})
// Intercept the response to rewrite absolute redirects against the base path.
// Is disabled when the request has no base path which means /absproxy is in use.
2020-10-21 01:05:58 +02:00
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
}
})