60 lines
No EOL
1.6 KiB
TypeScript
60 lines
No EOL
1.6 KiB
TypeScript
import Fastify from "fastify";
|
|
import FastifyFormBody from "@fastify/formbody";
|
|
import FastifyMultipart from "@fastify/multipart";
|
|
import FastifyCookie from "@fastify/cookie";
|
|
import FastifyView from "@fastify/view";
|
|
import FastifyStatic from "@fastify/static";
|
|
import Config from "./objects/Config";
|
|
import EJS from "ejs";
|
|
import { Console } from "hsconsole";
|
|
import Controller from "./controllers/Controller";
|
|
import HomeController from "./controllers/HomeController";
|
|
import Database from "./objects/Database";
|
|
import { join } from "path";
|
|
|
|
Console.customHeader(`EUS server started at ${new Date()}`);
|
|
|
|
const fastify = Fastify({
|
|
logger: false
|
|
});
|
|
|
|
fastify.register(FastifyView, {
|
|
engine: {
|
|
ejs: EJS
|
|
}
|
|
});
|
|
|
|
fastify.register(FastifyFormBody);
|
|
|
|
fastify.register(FastifyMultipart);
|
|
|
|
fastify.register(FastifyCookie, {
|
|
secret: Config.session.secret,
|
|
parseOptions: {
|
|
path: "/",
|
|
secure: true
|
|
}
|
|
});
|
|
|
|
fastify.register(FastifyStatic, {
|
|
root: join(__dirname, "wwwroot"),
|
|
//prefix: `${Config.ports.web}/static/`
|
|
});
|
|
|
|
fastify.setNotFoundHandler(async (_req, res) => {
|
|
return res.status(404).view("views/404.ejs", { });
|
|
});
|
|
|
|
new Database(Config.database.address, Config.database.port, Config.database.username, Config.database.password, Config.database.name);
|
|
|
|
Controller.FastifyInstance = fastify;
|
|
new HomeController();
|
|
|
|
fastify.listen({ port: Config.ports.web, host: "127.0.0.1" }, (err, address) => {
|
|
if (err) {
|
|
Console.printError(`Error occured while spinning up fastify:\n${err}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
Console.printInfo(`Fastify listening at ${address.replace("0.0.0.0", "localhost").replace("127.0.0.1", "localhost")}`);
|
|
}); |