-
Notifications
You must be signed in to change notification settings - Fork 29
/
app.js
33 lines (24 loc) · 871 Bytes
/
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
const express = require('express');
const path = require('path');
const morgan = require('morgan');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const authRouter = require('./routers/authRouter');
const viewRouter = require('./routers/viewRouter');
const errorController = require('./controllers/errorController');
const jwtSecret = process.env.JWT_SECRET;
const app = express();
app.use(cors());
app.use(morgan('tiny'));
//serve static files from react app
app.use(express.static(path.join(__dirname, 'react/build')));
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(cookieParser(jwtSecret));
app.use('/', viewRouter);
app.use('/auth/', authRouter);
app.get('*', (req, res) =>{
res.sendFile(path.join(__dirname+'/react/build/index.html'));
});
app.use(errorController);
module.exports = app;