-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.mjs
36 lines (31 loc) · 899 Bytes
/
app.mjs
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
import fs from "fs";
import http from "http";
import { middleware } from "astro-imagetools/ssr";
import { handler as ssrHandler } from "./dist/server/entry.mjs";
http
.createServer(async function (req, res) {
await ssrHandler(req, res, async (err) => {
if (err) {
res.writeHead(500);
res.end(err.toString());
} else {
const assetPath = `./dist/client${req.url}`;
if (fs.existsSync(assetPath)) {
const buffer = await fs.promises.readFile(assetPath);
res.writeHead(200);
res.end(buffer);
} else {
const buffer = await middleware(req, res);
if (buffer) {
res.writeHead(200);
res.end(buffer);
} else {
res.writeHead(404);
res.end();
}
}
}
});
})
.listen(8080);
console.log("Listening to Port 8080");