-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (28 loc) · 859 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require('cors')
const app = express();
const { database } = require('./config/database');
const documentation = require('./config/documentation');
// Database
mongoose.Promise = global.Promise;
mongoose.connect(database);
// Middleware
app.use(cors());
app.use(bodyParser.json());
// Routes
app.use('/lines', require('./routes/lines'));
app.use('/setup', require('./routes/setup'));
// API Documentation
app.all('/', (req, res) => {
res.status(200).json(documentation);
});
// Invalid url
app.all('*', (req, res) => {
res.status(404).json({ error: 'URL is not found' });
});
// Start the server
const port = process.env.PORT || 3000;
app.listen(port);
console.log(`Server listening at: ${port}`);