-- StoreAsset Demo -- -- Redbean is able to store files into its own executable structure. -- This is currently only supported on a Linux, Apple, and FreeBSD. -- -- By loading this page, your redbean will insert an immediate file into -- your redbean named `/hi`, which you can click the back button in the -- browser and view it on the listing page right afterwards! Write[[ redbean store asset demo

store asset demo

]] if IsPublicIp(GetClientAddr()) then Write[[

Bad request.

This HTTP endpoint self-modifies the web server. You're communicating wtith this redbean over a public network. Therefore redbean won't service this request.

]] elseif GetHostOs() == "WINDOWS" or GetHostOs() == "OPENBSD" or GetHostOs() == "NETBSD" then Write[[

Unsupported

Sorry! Redbean's Lua StoreAsset() function is only supported on Linux, Apple, and FreeBSD right now.

]] else StoreAsset('/hi', [[ StoreAsset() worked! This file was inserted into your redbean by the Lua StoreAsset() API which was invoked by you browsing to the /store-asset.lua page. Enjoy your self-modifying web server! ]]) Write[[

This Lua script has just stored a new file named /hi to your redbean zip executable. This was accomplished while the web server is running. It live updates, so if you click the back button in your browser, you should see /hi in the ZIP central directory listing, and you can send an HTTP message requesting it.

]] end Write[[

go back

]]