-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (37 loc) · 1.15 KB
/
server.js
File metadata and controls
46 lines (37 loc) · 1.15 KB
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
require('dotenv').config();
const express = require('express'),
morgan = require('morgan'),
compression = require('compression'),
mongoose = require('mongoose');
const app = express();
const PORT = process.env.PORT || 3001;
const routes = require('./routes');
// Middleware
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(morgan('tiny'));
app.use(compression());
// https://house-atl-api-dev.herokuapp.com/
app.use((req, res, next) => {
res.append('Access-Control-Allow-Origin', ['*']);
res.append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.append('Access-Control-Allow-Headers', 'Content-Type');
next();
});
app.use(routes);
// const mongoURI = 'mongodb://localhost/houseatl';
const mongoURI = process.env.MONGODB_URI || 'mongodb://localhost/houseatl';
mongoose
.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(res => console.log(
res.connections?.[0] ?
`Connected to ${mongoURI}...` :
`Could NOT connect to ${mongoURI}.`
))
.catch(err => console.log(err));
app.listen(PORT, () => {
console.log(`🌎 ==> API Server now listening on PORT ${PORT}!`);
});