import fastify from "fastify";
import fastifyStatic from "fastify-static";
import { join } from "path";

/**
 * Create the server instance
 */
let server = fastify();

/**
 * Serve static assets
 */
server.register(fastifyStatic, {
	root: join(__dirname, "../public")
});

/**
 * If a file is not found, return the web UI
 */
server.setNotFoundHandler((_, reply) => {
	console.log("Serving the file");
	return reply.sendFile("index.html");
});

/**
 * Serve the web UI
 */
server.listen(3201, "0.0.0.0");
console.log("Web UI is ready");
