forked from kimmyparkw/covidtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (56 loc) · 1.63 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//import our dependencies
const express = require('express')
const logger = require('morgan')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const session = require('express-session')
const passport = require('passport')
const path = require('path')
//intialize the app and setup dotenv
const app = express()
require('dotenv').config()
//Middleware Setup
app.use(logger('dev'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(
session({
key: process.env.SECRET_KEY,
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: true,
})
)
app.use(passport.initialize())
app.use(passport.session())
app.use(express.static('public'))
//Set the port to listen
const PORT = process.env.PORT || 3001
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`)
})
//ROUTES SETUP
//Root Route
app.get('/', (req, res) => {
res.send('Hello World! Welcome To Our Covid-19 Tracker')
})
const authRoutes = require('./routes/auth-routes')
app.use('/api/auth', authRoutes)
const userRoutes = require('./routes/user-routes')
app.use('/api/user', userRoutes)
const userStatesRouter = require('./routes/user-states');
app.use('/api/user/stats', userStatesRouter);
const statsRouter = require('./routes/stats-routes')
app.use('/api/stats', statsRouter)
//Send to React App
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'))
});
app.use((err, req, res, next) => {
console.log(err)
res.status(500).json({
error: err,
message: err.message
})
})