-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
24 lines (20 loc) · 799 Bytes
/
app.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
const express = require('express'),
app = express(),
cors = require('cors'),
mongoose = require('mongoose'),
myParser = require("body-parser"),
path = require('path');
//Setup
const apiRouter = require('./api');
const DATABASE_URI = process.env.DATABASE_URI || "mongodb://localhost/journal";
const PORT = process.env.PORT || 3001;
app.use(myParser.urlencoded({extended : true}));
app.use(myParser.json());
app.use(cors());
app.use(express.static(path.join(__dirname, 'client/build')));
mongoose.connect(DATABASE_URI, {useNewUrlParser: true, useUnifiedTopology: true}).catch(err => err);
app.use("/", apiRouter)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
app.listen(PORT, ()=> console.log(`App listens at ${PORT}`));