-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (26 loc) · 1.04 KB
/
app.js
File metadata and controls
35 lines (26 loc) · 1.04 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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
// eslint-disable-next-line no-unused-vars
let port;
if (process.env.ENV === 'Test') {
// eslint-disable-next-line no-unused-vars
const db = mongoose.connect('mongodb://localhost/rpg1_test', { useNewUrlParser: true, useUnifiedTopology: true });
port = process.env.PORT || 3050;
} else {
// eslint-disable-next-line no-unused-vars
const db = mongoose.connect('mongodb://localhost/rpg1', { useNewUrlParser: true, useUnifiedTopology: true });
port = process.env.PORT || 3000;
}
const Entry = require('./models/entryModel');
const postRouter = require('./routes/postsRouter')(Entry);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/api', postRouter);
app.get('/', (req, res) => {
res.send('Welcome to my RPG API');
});
// eslint-disable-next-line no-console
app.server = app.listen(port, () => { console.log(`running on port ${port}`); });
module.exports = app;