-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (31 loc) · 1.22 KB
/
server.js
File metadata and controls
39 lines (31 loc) · 1.22 KB
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
require('dotenv').config();
const express = require('express');
const path = require('path');
const logger = require('morgan');
const favicon = require('serve-favicon');
require('./config/database');
// Require controllers here
const app = express();
// add in when the app is ready to be deployed
// app.use(favicon(path.join(__dirname, 'build', 'favicon.ico')));
app.use(logger('dev'));
app.use(express.json());
app.use(favicon(path.join(__dirname, 'build', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'build'))); // this allows express to find the build folder
// Configure the auth middleware
// This decodes the jwt token, and assigns
// the user information to req.user
app.use(require('./config/auth'));
// api routes must be before the "catch all" route
app.use('/api/users', require('./routes/api/users'));
app.use('/api/fish', require('./routes/api/fish'));
app.use('/api/bugs', require('./routes/api/bugs'));
app.use('/api', require('./routes/api/caught'));
// "catch all" route
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 listening on port ${port}`);
});