-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (37 loc) · 1.04 KB
/
index.js
File metadata and controls
44 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import express from "express";
import logger from "morgan";
import chalk from "chalk";
import cors from "cors";
import { fileURLToPath } from "url";
import path, { dirname } from "path";
import "dotenv/config";
import { PORT, ORIGINS } from "./config/index.js";
import connectDB from "./database/index.js";
import notFound from "./middleware/notFound.js";
import error from "./middleware/error.js";
import indexRoutes from "./routes.js";
import "./helper/global.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, "public")));
app.use(
cors({
origin: ORIGINS,
credentials: true,
})
);
app.use("/", indexRoutes);
app.use(error);
app.use(notFound);
(async () => {
try {
await connectDB();
app.listen(PORT, () => {
console.log(chalk.blueBright(`Server listening on http://localhost:${PORT}`));
});
} catch (error) {}
})();