3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-05 10:17:20 +00:00
zeppelin/dashboard/serve.js
2025-06-01 19:37:10 +00:00

38 lines
886 B
JavaScript

import Fastify from "fastify";
import fastifyStatic from "@fastify/static";
import path from "node:path";
const fastify = Fastify({
// We already get logs from nginx, so disable here
logger: false,
});
fastify.addHook("preHandler", (req, reply, done) => {
if (req.url === "/env.js") {
reply.header("Content-Type", "application/javascript; charset=utf8");
reply.send(`window.API_URL = ${JSON.stringify(process.env.API_URL)};`);
}
done();
});
fastify.register(fastifyStatic, {
root: path.join(import.meta.dirname, "dist"),
wildcard: false,
});
fastify.get("*", (req, reply) => {
reply.sendFile("index.html");
});
fastify.listen({ port: 3002, host: '0.0.0.0' }, (err, address) => {
if (err) {
throw err;
}
console.log(`Server listening on ${address}`);
});
process.on("SIGTERM", () => {
fastify.close().then(() => {
process.exit(0);
});
});