-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (51 loc) · 1.25 KB
/
server.js
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
61
62
63
64
65
66
67
68
import ultra, { app, router } from "ultra";
import anybar from "anybar";
import postcss from "postcss";
import postcssNesting from "postcss-nesting";
import { Snelm } from "snelm";
const {
env,
readTextFile
} = Deno;
const importMapJson = await readTextFile("modules.json");
if (env.get("mode") === "dev") {
anybar("green");
}
const targets = [];
const snelm = new Snelm("oak", {
csp: null,
dnsPrefetchControl: null,
dontSniffMimetype: null,
expectCt: null,
featurePolicy: null,
frameguard: null,
hidePoweredBy: null
});
app.use(async (context, next) => {
context.response = snelm.snelm(context.request, context.response);
await next();
})
app.use(async (context, next) => {
await next();
const {
request: {
url: {
pathname
}
}
} = context;
if (pathname.endsWith(".css")) {
const cssFilePath = `./src${pathname.replace(/\.css$/, ".pcss")}`;
const cssText = await readTextFile(cssFilePath);
const output = (await postcss([postcssNesting]).process(cssText, { from: cssFilePath, map: true })).css;
context.response.headers.set("Content-type", "text/css")
context.response.body = output;
}
});
router.get("/sse", async (ctx) => {
const target = ctx.sendEvents();
targets.push(target);
});
ultra({
importmap: importMapJson
});