-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add index.ts for migrating from up to deno deploy
- Loading branch information
1 parent
523c6e3
commit af5cbfe
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |