From f5095443762e44054f52b47e6237f0438189eb54 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 10 Feb 2022 13:42:27 +0100 Subject: [PATCH] Added custom server --- .github/workflows/ci.yml | 3 +-- server/main.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 server/main.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe2b6b5..c9a6322 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,5 +32,4 @@ jobs: uses: denoland/deployctl@v1 with: project: lume-example - entrypoint: https://deno.land/std/http/file_server.ts - cwd: _site + entrypoint: server/main.ts diff --git a/server/main.ts b/server/main.ts new file mode 100644 index 0000000..bfb3f66 --- /dev/null +++ b/server/main.ts @@ -0,0 +1,29 @@ +import { Application, Router } from "https://deno.land/x/oak@v10.2.0/mod.ts"; + +const app = new Application(); + +// First we try to serve static files from the _site folder. If that fails, we +// fall through to the router below. +app.use(async (ctx, next) => { + try { + await ctx.send({ + root: `${Deno.cwd()}/_site`, + index: "index.html", + }); + } catch { + next(); + } +}); + +const router = new Router(); + +// The /api/time endpoint returns the current time in ISO format. +router.get("/api/time", (ctx) => { + ctx.response.body = { time: new Date().toISOString() }; +}); + +// After creating the router, we can add it to the app. +app.use(router.routes()); +app.use(router.allowedMethods()); + +await app.listen({ port: 8000 });