Last active
March 31, 2017 14:53
-
-
Save adamauckland/586cb326d2fd010250482bb0d34cde3a to your computer and use it in GitHub Desktop.
Revisions
-
adamauckland revised this gist
Mar 31, 2017 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ [ { "path": "/todo/list", "handler": "ListHandler", "verb": "get" }, { "path": "/todo/list/:id", "handler": "DetailHandler", "verb": "get" } ] -
adamauckland revised this gist
Mar 31, 2017 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ [ { 'path': '/todo/list', 'handler': 'ListHandler', 'verb': 'get }, { 'path': '/todo/list/:id', 'handler': 'DetailHandler', 'verb': 'get' } ] -
adamauckland created this gist
Mar 31, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ [ { path: '/todo/list', handler: 'ListHandler', verb: 'get }, { path: '/todo/list/:id', handler: 'DetailHandler', verb: 'get' } ] 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ var express = require('express'); var app = express(); // load config from file var config = require('config.json'); // handler mappings var handlers = { 'ListHandler': require('list-handler'), // different request handlers in different modules 'DetailHandler': require('detail-handler') }; config.forEach((route) => { // lookup the request handler from the handler mapping above so different paths can call different handlers. let routeHandler = handlers[route.handler]; // now set up a route at the path defined in the config pointing to the handler app[route.verb](route.path, routeHandler); });