Skip to content

Commit

Permalink
fix(app-vite): Fix SSR publicPath handling (#12972)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yusufkandemir authored Mar 29, 2022
1 parent 3285518 commit dee64f4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app-vite/lib/modes/ssr/ssr-devserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
* }}
*/
#appOptions = {}

// also update pwa-devserver.js when changing here
Expand Down Expand Up @@ -296,12 +304,10 @@ class SsrDevServer extends AppDevserver {
})
})

await injectMiddlewares(middlewareParams)

const { publicPath } = this.#appOptions

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

if (pathname.startsWith(publicPath) === true) {
next()
Expand Down Expand Up @@ -341,6 +347,8 @@ class SsrDevServer extends AppDevserver {
next()
})

await injectMiddlewares(middlewareParams)

const isReady = () => Promise.resolve()

const listenResult = await listen({
Expand Down

0 comments on commit dee64f4

Please sign in to comment.