-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (26 loc) · 854 Bytes
/
server.js
File metadata and controls
34 lines (26 loc) · 854 Bytes
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
const express = require('express');
const mongoose = require('mongoose');
const movies = require('./routes/api/movies');
const shows = require('./routes/api/shows')
const cors = require('cors');
const path = require('path');
const port = process.env.PORT || 4000;
const app = express();
// db config
const db = require('./config/keys').MONGODB_URI;
// connect to mongoDB
mongoose
.connect(db, {
useNewUrlParser: true,
})
.then(() => console.log('mongoDB connected'))
.catch(error => console.log(error));
// use routes
app.use(cors())
app.use('/api/movies', movies)
app.use('/api/shows', shows)
app.use(express.static(path.join(__dirname, "client", "build")))
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client", "build", "index.html"));
});
app.listen(port, () => console.log(`Server running on port ${port}`));