-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (32 loc) · 1.18 KB
/
app.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
require('dotenv').config()
const express = require('express')
const path = require('path');
require("./database/db")
const authRouter = require("./routes/auth")
const blogsRouter = require("./routes/blogs")
const createRouter = require("./routes/create")
const homereqRouter = require("./routes/homereq")
const operatorRouter = require('./routes/operators')
const app = express();
const port = process.env.PORT || 5000;
app.use(express.json())
// app.use((req, res, next) => {
// res.append('Access-Control-Allow-Origin', ['*']);
// res.append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
// res.append('Access-Control-Allow-Headers', 'Content-Type');
// next();
// });
if (process.env.NODE_ENV === 'production') {
app.use('/', express.static(path.join(__dirname, './frontend/build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname,'./frontend/build/index.html'));
});
}
app.use('/api/auth', authRouter);
app.use('/api/myblog', blogsRouter);
app.use('/api/homereq', homereqRouter);
app.use('/api/createblog', createRouter);
app.use('/api/operator',operatorRouter);
app.listen(port,() => {
console.log(`Server is running on port ${port}`)
})