Added custom server
This commit is contained in:
parent
91efb542fc
commit
f509544376
2 changed files with 30 additions and 2 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
@ -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
|
||||
|
|
29
server/main.ts
Normal file
29
server/main.ts
Normal file
|
@ -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 });
|
Loading…
Reference in a new issue