Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (40 loc) · 1.29 KB
/
Copy pathserver.js
File metadata and controls
53 lines (40 loc) · 1.29 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
47
48
49
50
51
52
53
"use strict"
const dotenv = require('dotenv')
dotenv.config();
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose') ;;
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.enable('trust proxy');
const swaggerUi = require('swagger-ui-express') ;
const swaggerDocument = require( './swagger.json')
// Rest Api
const port = process.env.PORT || 3000;
if (!process.env.MONGODB_URI) {
throw new Error('Invalid environment variable: "MONGODB_URI"')
}
const uri = process.env.MONGODB_URI;
mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
},(err, client) => {
if (err) return console.log(err);
console.log(`Connected to MongoDB: ${uri}`);
});
const bookings = require('./app/routes/Bookings.js');
app.use('/api/bookings', bookings);
const animals = require('./app/routes/Animals.js');
app.use('/api/animals', animals);
const tests = require('./app/routes/Tests.js');
app.use('/api/tests', tests);
const api = require('./app/routes/Api.js');
app.use('/api', api);
// Swagger
const options = {};
app.use('/', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options))
app.listen(port, () => {
console.log(`Example app is listening at ${port}`);
})