-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
39 lines (34 loc) · 1.4 KB
/
index.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
26
27
28
29
30
31
32
33
34
35
36
37
38
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 });