deno-deploy-example/server/main.ts
Sam Therapy c87abedc4d
Some checks reported errors
continuous-integration/drone/push Build encountered an error
ci / build (push) Failing after 13s
try
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2024-03-27 21:46:48 +01:00

29 lines
729 B
TypeScript

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()}`,
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 });