-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (29 loc) · 1.11 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
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
require('dotenv').config();
// Connect to db after the dotenv above
require('./config/database');
const app = express();
app.use(logger('dev'));
// Process data in body of request if
// Content-Type: 'application/json'
// and put that data on req.body
app.use(express.json());
app.use(favicon(path.join(__dirname, 'build', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'build')));
// middleware that adds the user object from a JWT to req.user
app.use(require('./config/checkToken'));
// Put all API routes here (before the catch-all)
app.use('/api/users', require('./routes/api/users'));
app.use('/api/anime', require('./routes/api/anime'));
// "catch-all" route that will match all GET requests
// that don't match an API route defined above
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
const port = process.env.PORT || 3001;
app.listen(port, function() {
console.log(`Express app running on port ${port}`);
});