-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (49 loc) · 1.31 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
42
43
44
45
46
47
48
49
50
51
52
53
54
// modules
require("dotenv").config();
const cors = require("cors");
const express = require("express");
const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
const path = require('path')
const app = express();
const server = require("http").createServer(app);
const io = require("socket.io")(server);
// variables
const userRoute = require("./src/routes/user.route");
const mailRoute = require("./src/routes/mail.route");
const dbURI = process.env.DB;
const port = process.env.PORT;
const corsOptions = {
origin: true,
credentials: true,
optionsSuccessStatus: 204,
};
// connect database
mongoose.connect(
dbURI,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
},
() => {
server.listen(port, () => {
console.log("SERVER UP & DATABASE CONNECTED");
});
}
);
// middlewares
app.use(cors(corsOptions));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
// routes
app.use(userRoute);
app.use(mailRoute);
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname + '/src/pages/index.html'));
});
app.get('/*', (req, res) => {
res.status(400).sendFile(path.join(__dirname + '/src/pages/404.html'))
})