-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (26 loc) · 1.1 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
40
41
42
43
44
45
46
47
48
require('dotenv').config()
console.log("Environment " + process.env.NODE_ENV)
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const path = require('path');
const db = require('./db')
const seedbankRouter = require('./routes/seedbank-router')
const app = express()
const apiPort = 5000
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cors())
app.use(bodyParser.json())
db.on('error', console.error.bind(console, 'MongoDB connection error:'))
//Static file declaration
app.use(express.static(path.join(__dirname, 'client/index')));
app.use('/api', seedbankRouter)
//production mode
if (process.env.NODE_ENV === 'production') {
console.log("In production")
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('*', (req, res) => { res.sendfile(path.join(__dirname = '/client/build/index.html'));
})}
//build mode
app.get('*', (req, res) => { res.sendfile(path.join(__dirname = '/client/public/index.html'))});
app.listen(process.env.PORT || apiPort, () => console.log(`Server running on port ${apiPort}`))