-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (31 loc) · 953 Bytes
/
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
import polka from "polka";
import sirv from "sirv";
import fs from "fs";
import { spaMiddleware } from "./util/middleware.js";
const dev = process.env.NODE_ENV !== "production";
if (!dev) {
import("./util/compile.js").then(({ compileAll }) => {
compileAll();
});
}
polka({
onNoMatch: spaMiddleware,
})
.use("/_ws.js", (req, res) => {
const buffer = fs.readFileSync("node_modules/ws/browser.js").toString();
res.writeHead(200, { "Content-Type": "application/javascript" });
return res.end(buffer);
})
.use("/_svelte", sirv("node_modules/svelte/", { dev: true }))
.use("/_client", sirv("build/client/", { dev: true }))
.use(sirv("static", { dev: true }))
.listen(3000, (err) => {
if (err) throw err;
console.log(`> http://localhost:3000`);
if (dev) {
import("./util/watch.js").then(({ default: watch }) => {
console.log("Watching for file changes...");
watch();
});
}
});