0.1.4 • Published 8 years ago
bearded-route-list v0.1.4
#Bearded Route List
I just want to know what the hell I'm doing
This attaches the express.Router()
instance to given endpoints inside of routes
along with building a list of all available endpoints along with the methods. See Example for use case and sample output
##Usage
yarn add bearded-route-list
##Import/Require
import baseList from 'bearded-route-list'
// OR
const baseList = require('bearded-route-list')
##Example
// Import the package
import baseList from 'bearded-route-list'
// Create routes/handlers
const UserRoute = express.Router(),
AuthRoute = express.Router(),
app = express()
// ...
// add endpoints to route
// ...
const routes = [
{
path: '/users',
handler: UserRoute
},
{
path: '/auth',
handler: AuthRoute
}
]
baseList(routes,app) // this will hook into the route '/'
// OR
baseList(routes, app, '/list') // this will hook into route '/list'
And going to '/'
will return this:
{
"/auth": {
"/login": {
"methods": {
"post": true
}
}
},
"/users": {
"/": {
"methods": {
"get": true,
"post": true
}
},
"/:_id": {
"methods": {
"delete": true,
"get": true,
"patch": true
}
}
}
}
##Description
(routes = [], app, base = '/')
With routes
being an array of objects with the following syntax:
{
path: String,
handler: express.Router()
}
App
being an express()
instance
base
being the route you want the list of endpoints to be at.