Support OnHttpRequest Lua callback

If your redbean `/.init.lua` file defines a global callable named
`OnHttpRequest` then redbean will delegate all serving control to
your function. You may then restore the default serving paths, by
calling the new `Route()`, `RouteHost()`, and `RoutePath()` APIs.

Closes #150
This commit is contained in:
Justine Tunney 2021-04-24 17:09:01 -07:00
parent dc6d11a031
commit 472b95fea3
13 changed files with 671 additions and 568 deletions

17
tool/net/demo/.init.lua Normal file
View file

@ -0,0 +1,17 @@
-- /.init.lua is loaded at startup in redbean's main process
HidePath('/usr/share/zoneinfo/')
function OnHttpRequest()
if HasParam('magic') then
Write('<p>\r\n')
Write('OnHttpRequest() has intercepted your request<br>\r\n')
Write('because you specified the magic parameter\r\n')
Write('<pre>\r\n')
Write(EscapeHtml(LoadAsset('/.init.lua')))
Write('</pre>\r\n')
else
Route()
end
SetHeader('Server', 'redbean!')
end