-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (25 loc) · 959 Bytes
/
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
require('dotenv').config();
require('./database/config');
const PORT = process.env.PORT || 5000;
const route= require('./Router/route');
const express = require('express');
const app = express();
const cors = require('cors');
const path= require('path');
// Middle ware
app.use(express.json());
app.use(cors());
if(process.env.NODE_ENV){
app.use(express.static(path.join(__dirname, './frontend/build')));
app.use("/api",route);
app.get('*',(req,res)=>{
res.sendFile(path.join(__dirname, './frontend/build/index.html'));
});
console.log(path.join(__dirname, './frontend/build'));
}else{
app.use("/api",route);
}
// cors issue: when we create api on backend and send request, request got block as due to security reasons in browser, we get cors error. browsser thinks that request from frontend and backend are different and throws cors error.
app.listen(PORT, () => {
console.log("Server is running at PORT 5000");
});