-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yash Walia
authored and
Yash Walia
committed
Apr 27, 2021
1 parent
bd5b303
commit 7727ef8
Showing
4 changed files
with
491 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"start": "node server.js" | ||
}, | ||
"dependencies": { | ||
"cors": "^2.8.5", | ||
"express": "^4.17.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
'use strict'; | ||
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'); | ||
|
||
var express = require('express'); | ||
var getArticle = require('./loaders/getArticle') | ||
var app = express(); | ||
var port = process.env.PORT || 3001; | ||
// 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) { | ||
console.log(req.params); | ||
res.send(getArticle.getRandom(req.params.num || 1, req.params.type)); | ||
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) { | ||
console.log(req.params); | ||
res.send(getArticle.getArticleFromId(req.params.id || 1, req.params.type)); | ||
res.status(200).send(getArticle.getArticle(req.params.type ,req.params.id || 1)); | ||
}); | ||
|
||
app.get('/', (req, res) => { | ||
res.status(200).status(200).send("Welcome to the DUNE API") | ||
}); | ||
|
||
app.listen(port, function () { | ||
console.log('Server running on port', port); | ||
}) | ||
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); |
Oops, something went wrong.