Skip to content

Commit

Permalink
Make Deno SSR Serve Custom 404 Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Aug 31, 2022
1 parent a1454d7 commit 554a6ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-brooms-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/deno': patch
---

Make Deno SSR Backend Render Custom 404 Pages
16 changes: 14 additions & 2 deletions packages/integrations/deno/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ export function start(manifest: SSRManifest, options: Options) {
Reflect.set(request, Symbol.for('astro.clientAddress'), ip);
return await app.render(request);
}


// If the request path wasn't found in astro,
// try to fetch a static file instead
const url = new URL(request.url);
const localPath = new URL('.' + url.pathname, clientRoot);
return fetch(localPath.toString());
const fileResp = await fetch(localPath.toString());

// If the static file can't be found
if (fileResp.status == 404) {
// Render the astro custom 404 page
return await app.render(request);

// If the static file is found
} else {
return fileResp;
}
};

const port = options.port ?? 8085;
Expand Down

0 comments on commit 554a6ae

Please sign in to comment.