-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
50 lines (39 loc) · 1.17 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
const express = require("express");
const bodyParser = require("body-parser");
const user = require("./routes/user");
const teacher = require("./routes/teacher");
const student = require("./routes/student");
const InitiateMongoServer = require("./config/db");
const cookieParser = require("cookie-parser");
const cors = require('cors');
var path = require("path");
require('dotenv').config()
// Initiate Mongo Server
InitiateMongoServer();
const app = express();
// PORT
const PORT = process.env.PORT || 5000;
// Middleware
app.use(bodyParser.json());
app.use(cookieParser());
app.use(cors());
/**
* Router Middleware
* Router - /user/*
* * Router - /teacher/*
* Method - *
*/
app.use("/user", user);
app.use("/teacher", teacher);
app.use("/student", student);
if (process.env.NODE_ENV === "production") {
// Serve any static files
app.use(express.static(path.join(__dirname, "/client/esm-client/build")));
// Handle React routing, return all requests to React app
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "/client/esm-client/build", "index.html"));
});
}
app.listen(PORT, (req, res) => {
console.log(`Server Started at PORT ${PORT}`);
});