-
Notifications
You must be signed in to change notification settings - Fork 12
/
server.js
37 lines (30 loc) · 1.3 KB
/
server.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
const express = require('express');
const cors = require('cors');
const app = express();
const PORT = process.env.PORT || 5000;
// const CONNECTION_URL = 'mongodb+srv://yashwalia:[email protected]/myFirstDatabase?retryWrites=true&w=majority'
const getArticle = require('./loaders/getArticle');
// app.use(bodyParser.json({ limit: "30mb", extended: true }));
// app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
app.all('*', function (req, res, next) {
res.set('Access-Control-Allow-Origin', '*');
next();
});
app.get('/:type/:num?', function (req, res) {
res.status(200).send(getArticle.getRandom(req.params.type, req.params.num || 1));
console.log(req.params)
});
app.get('/:type/id/:id?', function (req, res) {
res.status(200).send(getArticle.getArticle(req.params.type ,req.params.id || 1));
});
app.get('/', (req, res) => {
res.status(200).send("Welcome to the DUNE API")
});
app.listen(PORT, function () {
console.log('Server running on port', PORT);
});
// mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
// .then(() => app.listen(PORT, () => console.log(`Server running on port: ${PORT}`)))
// .catch((error) => console.log(error.message))
// mongoose.set('useFindAndModify', false);