From 087356f781b359230ffd8fdcec1e66a3b3969bb2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 27 Jun 2018 16:57:04 -0400 Subject: [PATCH] fix req.baseUrl synthesis --- src/middleware.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 78c49fc48..05bb025df 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -61,8 +61,13 @@ export default function middleware({ App, routes, store }: { const middleware = compose_handlers([ (req: Req, res: ServerResponse, next: () => void) => { if (req.baseUrl === undefined) { - req.baseUrl = req.originalUrl - ? req.originalUrl.slice(0, -req.url.length) + let { originalUrl } = req; + if (req.url === '/' && originalUrl[originalUrl.length - 1] !== '/') { + originalUrl += '/'; + } + + req.baseUrl = originalUrl + ? originalUrl.slice(0, -req.url.length) : ''; }