Skip to content

Commit

Permalink
fix: nicer qwik city env error during dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Sep 8, 2024
1 parent 5c203e1 commit f6164fa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/qwik/src/optimizer/src/plugins/vite-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export async function configureDevServer(
// we just needed the symbolMapper
return;
}

const hasQwikCity = server.config.plugins?.some(
(plugin) => plugin.name === 'vite-plugin-qwik-city'
);
// qwik middleware injected BEFORE vite internal middlewares
server.middlewares.use(async (req, res, next) => {
try {
Expand All @@ -119,8 +121,17 @@ export async function configureDevServer(
const url = new URL(req.originalUrl!, domain);

if (shouldSsrRender(req, url)) {
const { _qwikEnvData } = res as QwikViteDevResponse;
if (!_qwikEnvData && hasQwikCity) {
console.error(`not SSR rendering ${url} because Qwik City Env data did not populate`);
res.statusCode ||= 404;
res.setHeader('Content-Type', 'text/plain');
res.writeHead(res.statusCode);
res.end('Not a SSR URL according to Qwik City');
return;
}
const serverData: Record<string, any> = {
...(res as QwikViteDevResponse)._qwikEnvData,
..._qwikEnvData,
url: url.href,
};

Expand Down

0 comments on commit f6164fa

Please sign in to comment.