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()));
})
forked from erin-noe-payne/super-router
-
Notifications
You must be signed in to change notification settings - Fork 0
vmike245/super-router
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
It's super!
Resources
Stars
Watchers
Forks
Packages 0
No packages published
Languages
- JavaScript 100.0%