/
index.js
39 lines (32 loc) · 1.07 KB
/
index.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
39
//Express server
const express = require('express');
const app = express();
//front-end <--> back-end communication
const cors = require('cors');
//define port
const PORT = process.env.PORT || 5000;
//facilitate the joining of directory paths together
const path = require('path');
//middleware
app.use(cors()); //allows the front end to communicate with the back end (REACT <--> NODE)
//facilitate access to req.body
app.use(express.json());
//ensure correct directory paths in production
if(process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client/build')));
}
//ROUTES:
//manifest route
app.use("/manifest", require("./routes/manifest"));
//photos route
app.use("/photos", require("./routes/photos"));
//utilities route
app.use("/utilities", require("./routes/utilities"));
//display pages correctly when the page is refreshed
app.get('*', (request, response) => {
response.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
//start server
app.listen(PORT, () => {
console.log(`Server is starting on port ${PORT}.`);
});