-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.ts
25 lines (22 loc) · 923 Bytes
/
web.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Application, Context, Router, Status } from "https://deno.land/x/[email protected]/mod.ts";
import { getIcal } from "./ical.ts";
const router: Router = new Router();
router.get("/", async (ctx: Context) => {
console.log(`IP: ${ctx.request.ip}`);
const ical = await getIcal(2024);
if (ical) {
ctx.response.headers.set("content-type", "text/calendar; charset=utf-8");
ctx.response.status = Status.OK;
ctx.response.body = ical;
} else {
ctx.response.headers.set("content-type", "text/plain; charset=utf-8");
ctx.response.status = Status.NotFound;
ctx.response.body = "ical not found";
}
});
const app = new Application();
app.addEventListener("listen", (e) => console.log(`Listen: ${e.port}`));
app.use(router.routes());
app.use(router.allowedMethods());
app.listen({ port: 10101 });
// deno bundle --config ./deno.tsconfig.json --import-map deps.json formule1/web.ts formule1/deploy.ts