pkulchenko / fullmoon

Fast and minimalistic Redbean-based Lua web framework in one file.
MIT License
684 stars 30 forks source link

hand over route back to the redbean core if no matching fullmoon route #10

Closed fonghou closed 2 years ago

fonghou commented 2 years ago

Hi, thank you very much for writing this awesome library!

Would you think it's a good idea to replace https://github.com/pkulchenko/fullmoon/blob/f47bbbbe6edd8c1bf60ad5a029d828a68f52390a/fullmoon.lua#L881

with

return Route()

This would hand over route back to redbean core if no matching fullmoon route found. I feel redbean file path based routes (e.g. /foo/bar.lua) sometimes is very convenient to be used together with fullmoon.lua.

I've been using a local modified copy without issue. Wondering if it's a good idea to upstream a PR.

Thanks!

pkulchenko commented 2 years ago

@FongHou, thank you for the feedback! I thought about it earlier and decided against it, because there are some default handlers that may or may not be appropriate to be handled. For example, /statusz, folder index and some others.

If it is desirable to provide this behavior, then one can write fm.setRoute("/*catchall", fm.servePath) or fm.setRoute("/*catchall", fm.route); the former will skip /statusz and index handling.

There is another consideration that may be important in some cases. Right now redbean doesn't provide a way to intercept its internal ServeError call to serve a custom 404 (if desired), but using error2tmpl (as you referenced above) allows providing a custom template for 404 pages. This may change in the future, but given the current state, I think it's better to be explicit in handling default routes.

fonghou commented 2 years ago

I tried what you recommanded. It works great. Thank you for the quick response!

pkulchenko commented 2 years ago

Good to hear! I updated the documentation to cover this scenario.