From 1d289ffb10eeead6871bf8a6e1b94351b9597268 Mon Sep 17 00:00:00 2001 From: Yusuf Kandemir Date: Tue, 29 Mar 2022 01:21:26 +0300 Subject: [PATCH 1/4] fix(app-vite): Fix SSR publicPath check --- app-vite/lib/modes/ssr/ssr-devserver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app-vite/lib/modes/ssr/ssr-devserver.js b/app-vite/lib/modes/ssr/ssr-devserver.js index 94b405dd61b..0aba9464d59 100644 --- a/app-vite/lib/modes/ssr/ssr-devserver.js +++ b/app-vite/lib/modes/ssr/ssr-devserver.js @@ -300,7 +300,7 @@ class SsrDevServer extends AppDevserver { const { publicPath } = this.#appOptions - publicPath.length !== '/' && app.use((req, res, next) => { + publicPath !== '/' && app.use((req, res, next) => { const pathname = new URL(req.url).pathname || '/' if (pathname.startsWith(publicPath) === true) { From 346b855c2d86a1fb4047e515005f7da00db7ab8b Mon Sep 17 00:00:00 2001 From: Yusuf Kandemir Date: Tue, 29 Mar 2022 01:23:00 +0300 Subject: [PATCH 2/4] refactor(app-vite): Add JSDoc types for #appOptions --- app-vite/lib/modes/ssr/ssr-devserver.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app-vite/lib/modes/ssr/ssr-devserver.js b/app-vite/lib/modes/ssr/ssr-devserver.js index 0aba9464d59..d5d2ceb426b 100644 --- a/app-vite/lib/modes/ssr/ssr-devserver.js +++ b/app-vite/lib/modes/ssr/ssr-devserver.js @@ -82,6 +82,14 @@ class SsrDevServer extends AppDevserver { #viteServer #htmlWatcher #webserverWatcher + /** + * @type {{ + * port: number; + * publicPath: string; + * resolveUrlPath: import('../../../types').SsrMiddlewareResolve['urlPath']; + * render: (ssrContext: import('../../../types').QSsrContext) => Promise; + * }} + */ #appOptions = {} // also update pwa-devserver.js when changing here From ef9395cc0c996aaabfef4dbcc3c7a69e346d6242 Mon Sep 17 00:00:00 2001 From: Yusuf Kandemir Date: Tue, 29 Mar 2022 01:26:14 +0300 Subject: [PATCH 3/4] fix(app-vite): Call SSR injectMiddlewares at the right time to enable publicPath middleware --- app-vite/lib/modes/ssr/ssr-devserver.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app-vite/lib/modes/ssr/ssr-devserver.js b/app-vite/lib/modes/ssr/ssr-devserver.js index d5d2ceb426b..7de927c9db8 100644 --- a/app-vite/lib/modes/ssr/ssr-devserver.js +++ b/app-vite/lib/modes/ssr/ssr-devserver.js @@ -304,8 +304,6 @@ class SsrDevServer extends AppDevserver { }) }) - await injectMiddlewares(middlewareParams) - const { publicPath } = this.#appOptions publicPath !== '/' && app.use((req, res, next) => { @@ -349,6 +347,8 @@ class SsrDevServer extends AppDevserver { next() }) + await injectMiddlewares(middlewareParams) + const isReady = () => Promise.resolve() const listenResult = await listen({ From 97d47b7150ae75d855eb43c0c83e5d288a3765c1 Mon Sep 17 00:00:00 2001 From: Yusuf Kandemir Date: Tue, 29 Mar 2022 01:45:51 +0300 Subject: [PATCH 4/4] fix(app-vite): Correctly use WHATWG URL constructor Here is a lengthy discussion about the problem https://github.com/nodejs/node/issues/12682 --- app-vite/lib/modes/ssr/ssr-devserver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app-vite/lib/modes/ssr/ssr-devserver.js b/app-vite/lib/modes/ssr/ssr-devserver.js index 7de927c9db8..e29767fad18 100644 --- a/app-vite/lib/modes/ssr/ssr-devserver.js +++ b/app-vite/lib/modes/ssr/ssr-devserver.js @@ -307,7 +307,7 @@ class SsrDevServer extends AppDevserver { const { publicPath } = this.#appOptions publicPath !== '/' && app.use((req, res, next) => { - const pathname = new URL(req.url).pathname || '/' + const pathname = new URL(req.url, `http://${request.headers.host}`).pathname || '/' if (pathname.startsWith(publicPath) === true) { next()