From af5cbfea94f3f411ec2077fad24fca631a245c1e Mon Sep 17 00:00:00 2001 From: Rick Cogley Date: Fri, 20 Jan 2023 10:27:11 +0000 Subject: [PATCH] Add index.ts for migrating from up to deno deploy --- index.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 index.ts diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..b6a761d --- /dev/null +++ b/index.ts @@ -0,0 +1,39 @@ +import { Application } from "https://deno.land/x/oak/mod.ts"; + +const app = new Application(); + +// Logger +app.use(async (ctx, next) => { + await next(); + const rt = ctx.response.headers.get("X-Response-Time"); + console.log(`${ctx.request.method} ${ctx.request.url} - ${rt}`); +}); + +// Timing +app.use(async (ctx, next) => { + const start = Date.now(); + await next(); + const ms = Date.now() - start; + ctx.response.headers.set("X-Response-Time", `${ms}ms`); + ctx.response.headers.set("X-Custom-Header", "Rawr eSolia"); + ctx.response.headers.set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload"); + ctx.response.headers.set("X-Frame-Options", "SAMEORIGIN"); + ctx.response.headers.set("Referrer-Policy", "strict-origin"); + ctx.response.headers.set("X-Content-Type-Options", "nosniff"); + ctx.response.headers.set("X-Powered-By", "Blood Sweat Tears"); + ctx.response.headers.set("Permissions-Policy", "accelerometer=(), ambient-light-sensor=*, autoplay=(self), battery=(self), camera=(), cross-origin-isolated=*, fullscreen=*, geolocation=(self), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), usb=()"); +}); + +app.use(async (ctx) => { + try { + await ctx.send({ + root: `${Deno.cwd()}/html`, + index: "index.html", + }); + } catch { + ctx.response.status = 404; + ctx.response.body = "404 File not found"; + } +}); + +await app.listen({ port: 8000 });