Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const routes = [
- {
- routeName: '/forms',
- async method ({ response, activeUser }) {
- try {
- // anonymised
- } catch (err) {
- console.error(err)
- }
- }
- },
- {
- routeName: '/forms',
- reqMethod: 'POST',
- async method ({ response, activeUser, bodyData }) {
- // anonymised
- try {
- // anonymised
- } catch (err) {
- console.error(err)
- }
- }
- },
- {
- routeName: '/forms/:id',
- reqMethod: 'POST',
- async method ({ response, activeUser, bodyData, params }) {
- // anonymised
- try {
- // anonymised
- } catch (err) {
- console.error(err)
- }
- }
- },
- {
- routeName: '/forms/types',
- async method ({ response }) {
- try {
- // anonymised
- } catch (err) {
- console.error(err)
- }
- }
- }
- ]
- function matchRoute (routeName) {
- // match and return the matched object (dict) here, as well as the params
- // return { route, params }
- }
- const routesThatShouldMatch = [
- '/forms',
- '/forms/72',
- '/forms/types'
- ]
- routesThatShouldMatch.forEach(routeName => {
- const matchedRoute = matchRoute(routeName)
- console.log({
- route: matchedRoute.route,
- params: matchedRoute.params
- })
- })
Add Comment
Please, Sign In to add comment