Skip to content

Commit dee64f4

Browse files
fix(app-vite): Fix SSR publicPath handling (#12972)
* fix(app-vite): Fix SSR publicPath check * refactor(app-vite): Add JSDoc types for #appOptions * fix(app-vite): Call SSR injectMiddlewares at the right time to enable publicPath middleware * fix(app-vite): Correctly use WHATWG URL constructor Here is a lengthy discussion about the problem nodejs/node#12682
1 parent 3285518 commit dee64f4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

app-vite/lib/modes/ssr/ssr-devserver.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ class SsrDevServer extends AppDevserver {
8282
#viteServer
8383
#htmlWatcher
8484
#webserverWatcher
85+
/**
86+
* @type {{
87+
* port: number;
88+
* publicPath: string;
89+
* resolveUrlPath: import('../../../types').SsrMiddlewareResolve['urlPath'];
90+
* render: (ssrContext: import('../../../types').QSsrContext) => Promise<string>;
91+
* }}
92+
*/
8593
#appOptions = {}
8694

8795
// also update pwa-devserver.js when changing here
@@ -296,12 +304,10 @@ class SsrDevServer extends AppDevserver {
296304
})
297305
})
298306

299-
await injectMiddlewares(middlewareParams)
300-
301307
const { publicPath } = this.#appOptions
302308

303-
publicPath.length !== '/' && app.use((req, res, next) => {
304-
const pathname = new URL(req.url).pathname || '/'
309+
publicPath !== '/' && app.use((req, res, next) => {
310+
const pathname = new URL(req.url, `http://${request.headers.host}`).pathname || '/'
305311

306312
if (pathname.startsWith(publicPath) === true) {
307313
next()
@@ -341,6 +347,8 @@ class SsrDevServer extends AppDevserver {
341347
next()
342348
})
343349

350+
await injectMiddlewares(middlewareParams)
351+
344352
const isReady = () => Promise.resolve()
345353

346354
const listenResult = await listen({

0 commit comments

Comments
 (0)