-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.ts
60 lines (51 loc) · 1.8 KB
/
serve.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import site from "./_config.ts";
import Server from "lume/core/server.ts";
//import { basicAuth } from "lume/middlewares/basic_auth.ts";
import precompress from "lume/middlewares/precompress.ts";
import expires from "lume/middlewares/expires.ts";
import csp from "https://raw.githubusercontent.com/lumeland/experimental-plugins/main/csp/mod.ts";
import onDemand from "lume/middlewares/on_demand.ts";
import "./_preload.ts";
//import csp from "https://raw.githubusercontent.com/RickCogley/experimental-plugins/refs/heads/main/csp/mod.ts";
const server = new Server({
port: 8000,
root: `${Deno.cwd()}/_site`,
});
// Set the var in your Deno Deploy project environment variables.
// const myUSER_1_PASS = Deno.env.get("USER_1_PASS");
// const middleware = basicAuth({
// users: {
// "guest": `${myUSER_1_PASS}`,
// },
// errorMessage: "401 Unauthorized, contact site owner for access.",
// });
// server.use((req, next) => {
// if (isProtected(req)) {
// return middleware(req, next);
// }
// return next(req);
// });
// function isProtected(req) {
// const url = new URL(req.url);
// return url.pathname.includes("/private/");
// }
// assumes you are precompressing, say with the brotli plugin
server.use(precompress());
server.use(expires());
// pass your preferred security header options:
server.use(csp({
"Strict-Transport-Security": {
maxAge: 365 * 24 * 60 * 60, // one year
includeSubDomains: true,
preload: true,
},
"Referrer-Policy": ["no-referrer", "strict-origin-when-cross-origin"],
"X-Frame-Options": true,
"X-Content-Type-Options": true,
"X-XSS-Protection": true,
"X-Permitted-Cross-Domain-Policies": true,
"X-Powered-By": "Lume and sweat, blood, and tears",
}));
server.use(onDemand({ site }));
server.start();
console.log("Listening on http://localhost:8000");