-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
38 lines (31 loc) · 1.17 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
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
// Always require near the top
require('dotenv').config();
// Connect to the server
// Make sure that dotenv is already required
require('./config/database');
const app = express();
app.use(logger('dev'));
// body parser middleware - adds properties to req.body
app.use(express.json());
// Configure both serve-favicon & static
// middleware to server from the 'build' folder
app.use(favicon(path.join(__dirname, 'build', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'build')));
// Put API routes here, before the "catch all" route
app.use('/api/photos', require('./routes/api/photos'));
// The following "catch all" route (note the *)
// is necessary to return the index.html on ALL
// non-AJAX requests
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
// Configure express app to listen on port 3001
// to avoid conflicting with the react server
const port = process.env.PORT || 3001;
app.listen(port, function() {
console.log(`Express app running on port ${port}`);
});