import fastify from "fastify"; import fastifyStatic from "fastify-static"; import fastifyHttpProxy from "fastify-http-proxy"; import { join } from "path"; let server = fastify(); /** * If the app is in production mode, serve static assets. * If the app is in development mode, forward 404's to Vite. * NOTE: Static assets may be moved to nginx later... not sure yet */ if (process.env["NODE_ENV"] == "production") { server.register(fastifyStatic, { root: join(__dirname, "../public") }); server.setNotFoundHandler((request, reply) => { console.log("Replying with default"); return reply.sendFile("index.html"); }); } else { server.register(fastifyHttpProxy, { upstream: "http://localhost:3000" }); } server.get("/test", (request, reply) => { reply.send({result: "Success"}) }); server.listen(parseInt(process.env["SERVER_PORT"]), "0.0.0.0");