-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (43 loc) · 1.24 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('dotenv').config()
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const bodyParser = require('body-parser')
//Models
const Driver = require('./models/Driver');
const Race = require('./models/Race');
const Standings = require('./models/Standings');
const Circuit = require('./models/Circuit');
const app = express();
const port = 3003;
app.use(bodyParser.json())
app.use(cors())
app.get('/drivers', async (req, res) => {
const drivers = await Driver.find({})
res.send(drivers);
});
app.get('/races', async (req, res) => {
const races = await Race.find({});
res.send(races);
})
app.get('/standings', async (req, res) => {
const standings = await Standings.find({});
res.send(standings);
})
app.get('/circuits', async (req, res) => {
const circuits = await Circuit.find({});
res.send(circuits);
})
mongoose.set('debug', true);
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
dbName: 'F1',
useUnifiedTopology: true
})
.then(() => {
console.log('connected to MongoDB')
})
.catch((error) => {
console.log('error connection to MongoDB:', error.message)
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))