-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (37 loc) · 1.24 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
44
45
46
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const Grid = require('gridfs-stream');
const config = require('./config/db');
// const dbURI = config.get('mongoURI');
const connectDB = require('./config/db');
const path = require('path');
const eyeRoutes = require('./routes/api/eyes');
const imageRoutes = require('./routes/api/image');
const userRoutes = require('./routes/api/user');
const authRoutes = require('./routes/api/auth');
const PORT = process.env.PORT || 5000;
// connect DB
// let gfs;
// mongoose.createConnection(dbURI);
connectDB();
//middleware?
//need this middleware to parse body info from request
app.use(express.json({ extended: false }));
//routes
app.use('/api/user', userRoutes);
app.use('/api/auth', authRoutes);
app.use('/api/eyes', eyeRoutes);
app.use('/api/image', imageRoutes);
//serve static assets in production
if (process.env.NODE_ENV === 'production') {
// set static folder
app.use(express.static('my-react-app/build'));
app.get('*', (req, res) => {
res.sendFile(
path.resolve(__dirname, 'my-react-app', 'build', 'index.html')
);
});
}
// listen for server
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));