-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-server.js
30 lines (25 loc) · 960 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
30
const express = require('express');
const app = express();
const path = require('path'); // enables us to serve unix/windows w/o having to write multiple paths
const favicon = require('serve-favicon');
const logger = require('morgan');
const usersRoutes = require('./routes/api/users');
const ordersRoutes = require('./routes/api/orders');
const itemsRoutes = require('./routes/api/items');
app.use(express.json());
app.use((req, res, next) => {
res.locals.data = {};
next();
});
app.use(logger('dev'));
app.use(favicon(path.join(__dirname, 'public', 'img', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
app.use(require('./config/checkToken'));
app.use('/api/users', usersRoutes);
app.use('/api/orders', ordersRoutes);
app.use('/api/items', itemsRoutes);
// catch all -> if url doesn't match with any routes
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
module.exports = app;