404 properly
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2022-10-11 21:24:33 +02:00
parent e72f03da76
commit 63925530b1
Signed by: sam
GPG key ID: 4D8B07C18F31ACBD
3 changed files with 11 additions and 11 deletions

View file

@ -25,9 +25,9 @@ steps:
from_secret: DENO_DEPLOY_TOKEN
settings:
project: samme-blog
entrypoint: serve.ts
entrypoint: server.ts
production: true
include: dist,serve.ts
include: dist,server.ts
depends_on:
- "Build site"
when:

View file

@ -1,18 +1,18 @@
import { Application, Router } from "https://deno.land/x/oak@v11.1.0/mod.ts";
import { Application, httpErrors, Router } from "https://deno.land/x/oak@v11.1.0/mod.ts";
const app = new Application();
// First we try to serve static files from the dist folder. If that fails, we
// fall through to the router below.
app.use(async (ctx, next) => {
try {
await ctx.send({
root: `${Deno.cwd()}/dist`,
index: "index.html",
});
} catch {
await ctx.send({
root: `${Deno.cwd()}/dist`,
index: "index.html",
}).catch(async () => {
ctx.response.status = 404
ctx.response.body = await Deno.readTextFile(`${Deno.cwd()}/dist/404.html`);
next();
}
});
});
const router = new Router();

View file

@ -4,7 +4,7 @@ layout: layouts/base.tsx
url: /404.html
---
# You've found a dead end!
# Well, how did I get here?
Would you like to [return](/)?