const SuperRouter = require('super-router');
const app = new SuperRouter.App();
const router = new SuperRouter.Router();
router.addRoute({
path : '/cases',
methods : 'get',
handler : (opts) => {
const request = opts.request;
const response = opts.response;
return Database.getCases().then((cases)=>{
response.setBody(cases);
});
}
});
router.addRoute({
path : '/cases/:caseId',
methods : 'get',
handler : (opts) => {
const request = opts.request;
const response = opts.response;
return Database.getCaseById(request.routeParams.caseId).then((case)=>{
response.setBody(case);
});
}
});
app.then({
path : '/cases/externalId/:externalId(/*restOfRoute)',
handler : (opts) => {
const request = opts.request;
const response = opts.response;
return Database.getCaseByExternalId(request.routeParams.externalId).then((case)=>{
request.path = `/cases/${case.id}${request.routeParams.restOfRoute}`
});
}
});
app.then(router.match);
app.then(router.execute);
app.then((opts) => {
const request = opts.request;
const response = opts.response;
response.setBody(JSON.stringify(response.getBody()));
})
-
Notifications
You must be signed in to change notification settings - Fork 3
erin-noe-payne/super-router
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|