-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (34 loc) · 1.16 KB
/
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
43
const express = require('express');
require('./db/mongoose');
const cors = require('cors');
const categoryRouter = require('./routers/api/category');
const userRouter = require('./routers/api/user');
const cartRouter = require('./routers/api/cart');
const itemRouter = require('./routers/api/item');
const paymentRouter = require('./routers/api/payment');
const path = require('path');
const app = express();
app.use(express.json());
app.use(cors());
app.use('/api/categories', categoryRouter);
app.use('/api/users', userRouter);
app.use('/api/cart', cartRouter);
app.use('/api/items', itemRouter);
app.use('/api/payment', paymentRouter);
if (process.env.NODE_ENV === 'production') {
app.use((req, res, next) => {
if ((req.get('X-Forwarded-Proto') !== 'https')) {
res.redirect('https://' + req.get('Host') + req.url);
} else
next();
});
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'))
});
};
const port = process.env.PORT || 5000;
app.listen(port, err => {
if (err) throw Error;
console.log(`Server running on port ${port}`)
})