Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/qwik-city/middleware/cloudflare-pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,25 @@ export function qwikCity(render: Render, opts?: QwikCityCloudflarePagesOptions)
},
};

const handledResponse = await requestHandler<Response>(requestCtx, render, opts);
if (handledResponse) {
return handledResponse;
}

// check if the next middleware is able to handle this request
// useful if the request is for a static asset but app uses a catchall route
const nextResponse = await next();

if (nextResponse.status === 404) {
// next middleware unable to handle request
// send request to qwik city request handler
const handledResponse = await requestHandler<Response>(requestCtx, render, opts);
if (handledResponse) {
return handledResponse;
}

// qwik city did not have a route for this request
// respond with qwik city's 404 handler
const notFoundResponse = await notFoundHandler<Response>(requestCtx);
return notFoundResponse;
}

// use the next middleware's response
return nextResponse;
} catch (e: any) {
return new Response(String(e || 'Error'), {
Expand Down
18 changes: 13 additions & 5 deletions packages/qwik-city/middleware/netlify-edge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,25 @@ export function qwikCity(render: Render, opts?: QwikCityNetlifyOptions) {
},
};

const handledResponse = await requestHandler<Response>(requestCtx, render, opts);
if (handledResponse) {
return handledResponse;
}

// check if the next middleware is able to handle this request
// useful if the request is for a static asset but app uses a catchall route
const nextResponse = await next();

if (nextResponse.status === 404) {
// next middleware unable to handle request
// send request to qwik city request handler
const handledResponse = await requestHandler<Response>(requestCtx, render, opts);
if (handledResponse) {
return handledResponse;
}

// qwik city did not have a route for this request
// respond with qwik city's 404 handler
const notFoundResponse = await notFoundHandler<Response>(requestCtx);
return notFoundResponse;
}

// use the next middleware's response
return nextResponse;
} catch (e: any) {
return new Response(String(e || 'Error'), {
Expand Down