-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (35 loc) · 1.31 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
39
40
41
42
43
const express = require("express");
const path = require('path');
const species = require("./routes/api/species");
const whales = require("./routes/api/whales");
const researchers = require("./routes/api/researchers");
const organizations = require("./routes/api/organizations");
const sightings = require("./routes/api/sightings");
const sightings_whales = require("./routes/api/sightings_whales");
const app = express();
// Add req.body to all requests
app.use(express.json());
app.use(express.urlencoded({ extended: true }))
// Use the React client build (for Heroku deployment)
if (process.env.NODE_ENV === 'production'){
app.use(express.static(path.join(__dirname, 'client/build')));
}
console.log("path to build: " + path.join(__dirname, 'client/build'))
app.get("/", (req, res) =>{
res.send("Hello world")
});
// API routes
app.use("/api/species", species);
app.use("/api/whales", whales);
app.use("/api/researchers", researchers);
app.use("/api/organizations", organizations);
app.use("/api/sightings", sightings);
app.use("/api/sightings_whales", sightings_whales);
// Redirect all unidentified routes
app.get('/*', (req, res) => {
res.sendFile(path.resolve(__dirname + '/client/build/index.html'))
})
const port = process.env.PORT || 53588;
app.listen(port, ()=>{
console.log(`Listening on port: ${port}`);
});