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
|
|
|
|
2023-08-15 15:57:50 +03:00
|
|
|
import path from "path";
|
|
|
|
|
2023-08-14 13:05:34 +03:00
|
|
|
import Fastify from "fastify";
|
2023-08-15 15:57:50 +03:00
|
|
|
import fastifyStatic from "@fastify/static";
|
2023-08-14 15:39:40 +03:00
|
|
|
import fastifyView from "@fastify/view";
|
2023-08-16 10:36:04 +03:00
|
|
|
import fastifySwagger from "@fastify/swagger";
|
2023-08-14 15:39:40 +03:00
|
|
|
import ejs from "ejs";
|
2023-08-14 13:59:32 +03:00
|
|
|
|
2023-08-15 15:03:28 +03:00
|
|
|
import getRoute from "./routes/get";
|
2023-08-14 18:22:03 +03:00
|
|
|
import parseRoute from "./routes/parse";
|
2023-08-15 15:03:28 +03:00
|
|
|
import indexRoute from "./routes/index";
|
2023-08-16 09:43:43 +03:00
|
|
|
import rawHtml from "./routes/raw-html";
|
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
|
|
|
|
2023-08-15 15:57:50 +03:00
|
|
|
fastify.register(fastifyStatic, {
|
2023-08-15 17:34:39 +03:00
|
|
|
root: path.join(process.cwd(), "static"),
|
|
|
|
prefix: "/static/",
|
2023-08-15 15:57:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
fastify.register(fastifyView, {
|
2023-08-14 15:39:40 +03:00
|
|
|
engine: {
|
|
|
|
ejs: ejs,
|
2023-08-14 16:47:20 +03:00
|
|
|
},
|
2023-08-13 20:38:33 +03:00
|
|
|
});
|
|
|
|
|
2023-08-16 10:36:04 +03:00
|
|
|
await fastify.register(fastifySwagger, {
|
|
|
|
swagger: {
|
|
|
|
info: {
|
|
|
|
title: "Dottxt",
|
|
|
|
version: "1.0.0",
|
|
|
|
},
|
|
|
|
externalDocs: {
|
|
|
|
url: "https://github.com/dottxt/dottxt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-08-15 15:03:28 +03:00
|
|
|
fastify.register(indexRoute);
|
|
|
|
fastify.register(getRoute);
|
2023-08-14 16:44:23 +03:00
|
|
|
fastify.register(parseRoute);
|
2023-08-16 09:43:43 +03:00
|
|
|
fastify.register(rawHtml);
|
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();
|