pi-web 0.3.9 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/server/server.js
CHANGED
|
@@ -118,6 +118,17 @@ const server = createServer((req, res) => {
|
|
|
118
118
|
serveFile(filePath, res);
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
+
const acceptsHtml = (req.headers.accept ?? "").includes("text/html");
|
|
122
|
+
if (req.method === "GET" && !url.pathname.startsWith("/api/") && acceptsHtml) {
|
|
123
|
+
if (!existsSync(htmlPath)) {
|
|
124
|
+
res.writeHead(503, { "Content-Type": "text/plain" });
|
|
125
|
+
res.end("frontend not built. run: npm run build");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
129
|
+
res.end(htmlCache ?? readFileSync(htmlPath, "utf-8"));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
121
132
|
}
|
|
122
133
|
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
123
134
|
res.end("not found");
|