Allows for a subsection of your dispatched urls to be passed through other a pre-request filter, optionally pick up an new presenter class,
and then be dispatched to their own handlers.
/+
// a long-form filter function
bool permissionCheck(DispatcherData)(DispatcherData dd) {
// you are permitted to call mutable methods on the Cgi object
// Note if you use a Cgi subclass, you can try dynamic casting it back to your custom type to attach per-request data
// though much of the request is immutable so there's only so much you're allowed to do to modify it.
if(checkPermissionOnRequest(dd.cgi)) {
return true; // OK, allow processing to continue
} else {
dd.presenter.renderBasicError(dd.cgi, 403); // reply forbidden to the requester
return false; // and stop further processing into this subsection
}
}
+/// but you can also do short-form filters:boolpermissionCheck(Cgicgi) {
return ("ok"incgi.get) !isnull;
}
// handler for the subsectionclassAdminClass : WebObject {
intfoo() { return5; }
}
// handler for the main siteclassTheMainSite : WebObject {}
mixinDispatcherMain!(
"/admin".dispatchSubsection!(
// converts our short-form filter into a long-form filterpassFilterOrIssueError!(permissionCheck, 403),
// can use a new presenter if wanted for the subsectionKeepExistingPresenter,
// and then provide child route dispatchers"/".serveApi!AdminClass
),
// and back to the top level"/".serveApi!TheMainSite
);
Note you can encapsulate sections in files like this:
autoadminDispatcher(stringurlPrefix) {
returnurlPrefix.dispatchSubsection!(
....
);
}
mixinDispatcherMain!(
"/admin".adminDispatcher,
// and so on
)
If you want no filter, you can pass (cgi) => true as the filter to approve all requests.
If you want to keep the same presenter as the parent, use KeepExistingPresenter as the presenter argument.
Allows for a subsection of your dispatched urls to be passed through other a pre-request filter, optionally pick up an new presenter class, and then be dispatched to their own handlers.
Note you can encapsulate sections in files like this:
If you want no filter, you can pass (cgi) => true as the filter to approve all requests.
If you want to keep the same presenter as the parent, use KeepExistingPresenter as the presenter argument.