forked from jillianguerra/home-depot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-server.js
29 lines (25 loc) · 983 Bytes
/
app-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
const express = require('express')
const app = express()
const path = require('path')
const favicon = require('serve-favicon')
const logger = require('morgan')
app.use(express.json()) // req.body
app.use((req, res, next) => {
res.locals.data = {}
next()
})
app.use(logger('dev'))
app.use(favicon(path.join(__dirname, 'public', 'img','pokeball-favicon.png')))
app.use(express.static(path.join(__dirname, 'public')))
// Check if token and create req.user
app.use(require('./config/checkToken'));
// Put API routes here, before the "catch all" route
app.use('/api/users', require('./routes/api/users'));
// Protect the API routes below from anonymous users
const ensureLoggedIn = require('./config/ensureLoggedIn');
app.use('/api/pokemon', ensureLoggedIn, require('./routes/api/pokemon'));
app.use('/api/orders', ensureLoggedIn, require('./routes/api/orders'));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'))
})
module.exports = app