Skip to content

Commit

Permalink
Add index.ts for migrating from up to deno deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCogley committed Jan 20, 2023
1 parent 523c6e3 commit af5cbfe
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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 });

0 comments on commit af5cbfe

Please sign in to comment.