* feat: add table employment office * feat: add tag * feat: add employment office * chore: migrations * feat: order employment office * feat: delete old employment office when special got added
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import "dotenv/config";
|
|
import cors from "cors";
|
|
import express, { json, urlencoded } from "express";
|
|
import error from "./middlewares/error";
|
|
import morgan from "./middlewares/morgan";
|
|
import { RegisterRoutes } from "./routes";
|
|
import { initEmploymentOffice, initThailandAreaDatabase } from "./utils/thailand-area";
|
|
import { initFirstAdmin } from "./utils/database";
|
|
import { apiReference } from "@scalar/express-api-reference";
|
|
import { initSchedule } from "./services/schedule";
|
|
|
|
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
|
|
const APP_PORT = +(process.env.APP_PORT || 3000);
|
|
|
|
(async () => {
|
|
const app = express();
|
|
|
|
await initThailandAreaDatabase();
|
|
await initFirstAdmin();
|
|
await initEmploymentOffice();
|
|
|
|
initSchedule();
|
|
|
|
const originalSend = app.response.json;
|
|
|
|
app.response.json = function (body: unknown) {
|
|
this.app.locals.response = body;
|
|
return originalSend.call(this, body);
|
|
};
|
|
|
|
app.use(cors());
|
|
app.use(json());
|
|
app.use(urlencoded({ extended: true }));
|
|
app.use(morgan);
|
|
|
|
app.use("/", express.static("static"));
|
|
app.use("/api-docs", apiReference({ theme: "kepler", spec: { url: "/api/openapi" } }));
|
|
|
|
RegisterRoutes(app);
|
|
|
|
app.get("*", (_, res) =>
|
|
res.status(404).send({
|
|
status: 404,
|
|
message: "Route not found.",
|
|
devMessage: "unknown_url",
|
|
}),
|
|
);
|
|
|
|
app.use(error);
|
|
|
|
app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
|
|
})();
|