txtdot/src/app.ts

50 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-08-13 20:38:33 +03:00
import { IConfigService } from "./config/config.interface";
import { ConfigService } from "./config/config.service";
2023-08-14 13:42:13 +03:00
import path from "path";
2023-08-14 13:05:34 +03:00
import Fastify from "fastify";
import fastifyStatic from "@fastify/static";
import fastifyView from "@fastify/view";
import ejs from "ejs";
2023-08-14 13:59:32 +03:00
import getRoute from "./routes/get";
2023-08-14 18:22:03 +03:00
import parseRoute from "./routes/parse";
import indexRoute from "./routes/index";
2023-08-14 13:59:32 +03:00
2023-08-13 20:38:33 +03:00
class App {
config: IConfigService;
2023-08-14 13:42:13 +03:00
2023-08-13 20:38:33 +03:00
constructor() {
this.config = new ConfigService();
}
2023-08-14 13:42:13 +03:00
2023-08-14 13:03:19 +03:00
async init() {
const fastify = Fastify({
logger: true,
});
2023-08-13 20:38:33 +03:00
fastify.register(fastifyStatic, {
2023-08-15 17:34:39 +03:00
root: path.join(process.cwd(), "static"),
prefix: "/static/",
});
fastify.register(fastifyView, {
engine: {
ejs: ejs,
},
2023-08-13 20:38:33 +03:00
});
fastify.register(indexRoute);
fastify.register(getRoute);
2023-08-14 16:44:23 +03:00
fastify.register(parseRoute);
2023-08-13 21:39:23 +03:00
2023-08-14 16:44:23 +03:00
fastify.listen({ port: Number(this.config.get("PORT")) }, (err) => {
err && console.log(err);
2023-08-13 20:38:33 +03:00
});
}
}
const app = new App();
app.init();