-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set default resource #22
Comments
That's very clever, you're rewriting the url path on the request. I had planned on adding the ability to define a particular resource as the base resource. This would allow you to reference a page with As for whether the above code is good for defining a default result for a particular resource, I suppose if it works then it's great. I like how it's so well commented! An alternative would be to define a function fetchPage (db, slug) {
return db.fetchOne({ slug: slug });
}
exports.getIndex = function (req, res) {
return fetchPage(req.db, 'home');
};
exports.get = function (req, res) {
return fetchPage(req.db, req.params.id);
}; I never thought of it before, but I suppose this could be a good feature to bake into Synth. If you don't need an index method for a resource, you can define a default id and call the |
What I don't like is the need to define the If we can just intercept a 404 we can re-route the request to a default resource method. WDYT? |
You could do the following: ...
module.exports = synth();
// Catch remaining unhandled requests
synth.app.get('/*', function (req, res) {
// Send back a 302 redirect
res.redirect('/pages/home');
}); |
Cool... I'll try this one, thanks! |
I'm trying to have synth returning a default resource.
The following code in the
back/back-app.js
works, is there a better way to do it?The text was updated successfully, but these errors were encountered: