Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c85d0d3

Browse files
Fix routing for Express 5
1 parent 12461a6 commit c85d0d3

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

‎src/node/routes/index.ts‎

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,51 +79,48 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
7979
app.router.use(common)
8080
app.wsRouter.use(common)
8181

82-
app.router.use(async (req, res, next) => {
82+
app.router.use(/.*/,async (req, res, next) => {
8383
// If we're handling TLS ensure all requests are redirected to HTTPS.
8484
// TODO: This does *NOT* work if you have a base path since to specify the
8585
// protocol we need to specify the whole path.
8686
if (args.cert && !(req.connection as tls.TLSSocket).encrypted) {
8787
return res.redirect(`https://${req.headers.host}${req.originalUrl}`)
8888
}
89+
next()
90+
})
8991

90-
// Return security.txt.
91-
if (req.originalUrl === "/security.txt" || req.originalUrl === "/.well-known/security.txt") {
92-
const resourcePath = path.resolve(rootPath, "src/browser/security.txt")
93-
res.set("Content-Type", getMediaMime(resourcePath))
94-
return res.send(await fs.readFile(resourcePath))
95-
}
96-
97-
// Return robots.txt.
98-
if (req.originalUrl === "/robots.txt") {
99-
const resourcePath = path.resolve(rootPath, "src/browser/robots.txt")
100-
res.set("Content-Type", getMediaMime(resourcePath))
101-
return res.send(await fs.readFile(resourcePath))
102-
}
92+
app.router.get(["/security.txt", "/.well-known/security.txt"], async (_, res) => {
93+
const resourcePath = path.resolve(rootPath, "src/browser/security.txt")
94+
res.set("Content-Type", getMediaMime(resourcePath))
95+
res.send(await fs.readFile(resourcePath))
96+
})
10397

104-
next()
98+
app.router.get("/robots.txt", async (_, res) => {
99+
const resourcePath = path.resolve(rootPath, "src/browser/robots.txt")
100+
res.set("Content-Type", getMediaMime(resourcePath))
101+
res.send(await fs.readFile(resourcePath))
105102
})
106103

107104
app.router.use("/", domainProxy.router)
108105
app.wsRouter.use("/", domainProxy.wsRouter.router)
109106

110-
app.router.all("/proxy/:port/:path(.*)?", async (req, res) => {
107+
app.router.all("/proxy/:port{/*path}", async (req, res) => {
111108
await pathProxy.proxy(req, res)
112109
})
113-
app.wsRouter.get("/proxy/:port/:path(.*)?", async (req) => {
114-
await pathProxy.wsProxy(req as WebsocketRequest)
110+
app.wsRouter.get("/proxy/:port{/*path}", async (req) => {
111+
await pathProxy.wsProxy(req as unknownasWebsocketRequest)
115112
})
116113
// These two routes pass through the path directly.
117114
// So the proxied app must be aware it is running
118115
// under /absproxy/<someport>/
119-
app.router.all("/absproxy/:port/:path(.*)?", async (req, res) => {
116+
app.router.all("/absproxy/:port{/*path}", async (req, res) => {
120117
await pathProxy.proxy(req, res, {
121118
passthroughPath: true,
122119
proxyBasePath: args["abs-proxy-base-path"],
123120
})
124121
})
125-
app.wsRouter.get("/absproxy/:port/:path(.*)?", async (req) => {
126-
await pathProxy.wsProxy(req as WebsocketRequest, {
122+
app.wsRouter.get("/absproxy/:port{/*path}", async (req) => {
123+
await pathProxy.wsProxy(req as unknownasWebsocketRequest, {
127124
passthroughPath: true,
128125
proxyBasePath: args["abs-proxy-base-path"],
129126
})

‎src/node/routes/vscode.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ router.get("/manifest.json", async (req, res) => {
175175
const appName = req.args["app-name"] || "code-server"
176176
res.writeHead(200, { "Content-Type": "application/manifest+json" })
177177

178-
returnres.end(
178+
res.end(
179179
replaceTemplates(
180180
req,
181181
JSON.stringify(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /