-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (36 loc) · 1.15 KB
/
index.js
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
require("dotenv").config();
const express = require("express");
const path = require("path");
const compression = require("compression");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const corsOptions = require('./corsOptions/corsOptions');
const mongoose = require("mongoose");
const apiRouter = require("./routers/apiRouter");
const clientRouter = require("./routers/clientRouter");
const PORT = process.env.API_PORT;
const link = `${process.env.API_URL}`;
const url = process.env.MONGO_URL;
const app = express();
app.use(express.json());
app.use(cookieParser());
// app.use(cors(corsOptions));
app.use("/api/mailer", apiRouter);
app.use(compression());
app.use(express.static(path.join(process.cwd(), "public")));
app.use("/", clientRouter);
const start = async () => {
try {
await mongoose
.connect(url, { dbName: "Auth" })
.catch((e) => { console.log(e) });
} catch (e) {
console.log(e);
process.exit(1);
}
};
start();
app.listen(PORT, () => {
console.log('\x1b[36m%s\x1b[0m', '\nExpress server has been started at the port ', PORT);
console.log(`\n Link to the site \x1b[35m${link}\x1b[0m`);
});