Skip to content

Commit

Permalink
fix: ensure correct url is used when used as a sub-app
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 23, 2020
1 parent cf0a4eb commit 0e4770a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ export function use (

export function createHandle (stack: Stack): PHandle {
return async function handle (req: IncomingMessage, res: ServerResponse) {
req.url = req.url || '/'
const originalUrl = (req as any).originalUrl = (req as any).originalUrl || req.url || '/'
// @ts-ignore express/connect compatibility
req.originalUrl = req.originalUrl || req.url || '/'
const reqUrl = req.url || '/'
for (const layer of stack) {
if (layer.route.length) {
if (!originalUrl.startsWith(layer.route)) {
if (!reqUrl.startsWith(layer.route)) {
continue
}
req.url = originalUrl.substr(layer.route.length) || '/'
req.url = reqUrl.substr(layer.route.length) || '/'
}
if (layer.match && !layer.match(req.url as string, req)) {
continue
Expand Down

0 comments on commit 0e4770a

Please sign in to comment.