Created
November 22, 2018 04:27
-
-
Save way2datta/a8c7fdb90d6f5bab445f8c801e09d136 to your computer and use it in GitHub Desktop.
List down endpoints urls and http verbs that was built by using Node + Express
This file contains hidden or 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
const express = require('express'); | |
import routes from './routes/rest-api'; | |
const app = express(); | |
const port = 3000; | |
const hostUrl = "http://localhost:3000" | |
app.use('/', routes); | |
routes.stack.forEach(function (element) { | |
console.log(getHttpVerb(element.route) + " " + hostUrl + element.route.path); | |
}); | |
function getHttpVerb(route) { | |
if (route.methods.delete) { | |
return "HTTP DELETE"; | |
} | |
if (route.methods.post) { | |
return "HTTP POST "; | |
} | |
if (route.methods.put) { | |
return "HTTP PUT "; | |
} | |
return "HTTP GET "; | |
} | |
app.listen(port, () => console.log(`Example app listening on port ${port}!`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment