-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (42 loc) · 1.34 KB
/
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const mongoose = require('mongoose');
const path = require('path');
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const dotenv = require('dotenv').config();
mongoose.Promise = global.Promise;
// solve eslint error
const logger = console;
// const connect = mongoose.connect('mongodb://localhost/urlShortner', { useMongoClient: true });
const connect = mongoose.connect(
`${process.env.MONGODB_URI}`,
{ useMongoClient: true }
);
connect
.then(() => {
logger.log('connection to mongoose sucessfull');
})
.catch(err => {
logger.log('ther was an error connecting to mongoose');
logger.log(err);
});
const corsOptions = {
origin: true,
methods: 'GET, HEAD, PUT, PATCH, POST, DELETE',
preflightContinue: true,
optionsSuccessStatus: 204,
credentials: true // enable set cookie
};
const app = express();
// serves build from npm run build
app.use(express.static(path.join(__dirname, 'client/build')));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors(corsOptions));
const { routes } = require('./api/routes/routes');
routes(app);
app.listen(process.env.PORT, '0.0.0.0', () => {
// eslint-disable-next-line
logger.log(`server running on port ${process.env.PORT}`);
// console.log('mongo uri: ', process.env.MONGODB_URI);
});