summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/sharp-brooms-drum.md5
-rw-r--r--packages/integrations/deno/src/server.ts16
-rw-r--r--packages/integrations/deno/test/basics.test.js15
-rw-r--r--packages/integrations/deno/test/fixtures/basics/src/pages/404.astro1
4 files changed, 35 insertions, 2 deletions
diff --git a/.changeset/sharp-brooms-drum.md b/.changeset/sharp-brooms-drum.md
new file mode 100644
index 000000000..64c0d26b2
--- /dev/null
+++ b/.changeset/sharp-brooms-drum.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/deno': patch
+---
+
+Make Deno SSR Backend Render Custom 404 Pages
diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts
index b18e6034c..cf9c1cfd4 100644
--- a/packages/integrations/deno/src/server.ts
+++ b/packages/integrations/deno/src/server.ts
@@ -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;
diff --git a/packages/integrations/deno/test/basics.test.js b/packages/integrations/deno/test/basics.test.js
index aee9dd1f3..c883fc8ae 100644
--- a/packages/integrations/deno/test/basics.test.js
+++ b/packages/integrations/deno/test/basics.test.js
@@ -27,6 +27,21 @@ Deno.test({
});
Deno.test({
+ name: 'Custom 404',
+ async fn() {
+ await startApp(async () => {
+ const resp = await fetch('http://127.0.0.1:8085/this-does-not-exist');
+ assertEquals(resp.status, 404);
+ const html = await resp.text();
+ assert(html);
+ const doc = new DOMParser().parseFromString(html, `text/html`);
+ const header = doc.querySelector('#custom-404');
+ assert(header, 'displays custom 404');
+ });
+ },
+});
+
+Deno.test({
name: 'Loads style assets',
async fn() {
await startApp(async () => {
diff --git a/packages/integrations/deno/test/fixtures/basics/src/pages/404.astro b/packages/integrations/deno/test/fixtures/basics/src/pages/404.astro
new file mode 100644
index 000000000..cc1c5761e
--- /dev/null
+++ b/packages/integrations/deno/test/fixtures/basics/src/pages/404.astro
@@ -0,0 +1 @@
+<h1 id="custom-404">Custom 404 Page</h1>