-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (25 loc) · 849 Bytes
/
app.js
File metadata and controls
31 lines (25 loc) · 849 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
const http = require('http');
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const config = require('./services/config.js');
const bodyParser = require('body-parser');
const app = express();
const server = new http.Server(app);
app.use(cors());
app.options('*', cors());
function listen() {
server.listen(config.get('port'));
console.log(`Server listening on port ${config.get('port')}`);
}
// Database connection
function connect() {
return mongoose.connect(config.get('mongodb:uri')).connection;
}
app.use(bodyParser.json({ type: ['json', 'application/vnd.api+json'] }));
app.use(bodyParser.urlencoded({ extended: false }));
connect()
.on('error', console.log)
.on('disconnected', connect)
.once('open', listen);
app.use('/api/articles', require('./routes/articles.js'));