-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (32 loc) · 876 Bytes
/
server.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
// Modules
const express = require('express');
const dotenv = require("dotenv");
const cors = require("cors");
const morgan = require("morgan");
const fs = require('fs');
// Routers
const mainRoute = require("./routes/mainRouter");
//configure env
dotenv.config();
// Cors options
const corsOptions = {
origin: ['http://192.168.1.180:3000', 'http://localhost:3000', process.env.FRONTEND_URI],
credentials: true,
optionSuccessStatus: 200,
};
const app = express();
//middelwares
app.use(cors(corsOptions));
app.use(express.json());
app.use(morgan("dev"));
//rest api
app.get("/", (req, res) => {
res.send("Successful request. Try /api/v1/sendMails for products page.");
});
app.use("/api/v1/sendMails", mainRoute);
//PORT
const PORT = process.env.PORT || 5000;
// Start the server
app.listen(PORT, () => {
console.log(`Server Running on port ${PORT}`);
});