47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import express, { Express } from "express";
|
|
import dotenv from "dotenv";
|
|
import bodyParser from "body-parser";
|
|
import cors from "cors";
|
|
import fs from "fs-extra";
|
|
|
|
import logger from "./src/logger/logger";
|
|
import syncModels from "./src/models";
|
|
|
|
import websiteRoutes from "./src/routes/websiteRoutes";
|
|
import { fstat } from "fs-extra";
|
|
|
|
dotenv.config();
|
|
|
|
const app: Express = express();
|
|
const host = process.env.HOST || "localhost";
|
|
const port = Number(process.env.PORT) || 3000;
|
|
|
|
// TODO: setup cors
|
|
app.use(cors());
|
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use("/api/v1/website", websiteRoutes);
|
|
|
|
app.use((req, res, next) => {
|
|
console.log("req not found, path:", req.path);
|
|
res.status(404).send("not found");
|
|
});
|
|
|
|
app.use((err: any, req: any, res: any, next: any) => {
|
|
console.log("req err", err.stack);
|
|
res.status(500).send({ err: "invalid request" });
|
|
});
|
|
|
|
syncModels();
|
|
|
|
// create tmp folder if not exists
|
|
|
|
fs.mkdir(process.env.TMP_DIR as string, { recursive: true }, (err) => {
|
|
if (err) throw err;
|
|
});
|
|
|
|
app.listen(port, host, () =>
|
|
logger.info(`⚡️[server]: Server is running at http://${host}:${port}`)
|
|
);
|