package.path = package.path .. ";.lua/?.lua" package.path = package.path .. ";src/.lua/?.lua" package.path = package.path .. ";middleware/?.lua" package.path = package.path .. ";cmd/?.lua" print = function(...) Log(kLogInfo, ... or "''") end -- nice redbean logging from now on util = require "util" json = require "json" -- special script called by main redbean process at startup HidePath('/usr/share/zoneinfo/') HidePath('/usr/share/ssl/') dir = require "opendirectory" -- create app = require("soakbean") { bin = "./xrforge.com", bindir = arg[-1]:gsub("xrforge.com",""), cache = {}, opts = {}, cmd={ help = {file="cmd/help.lua", info="display all possible flags"}, server = {file="cmd/server.lua", info="starts the webserver"} } } -- api skeleton (implemented via soakbean's app.on(...)) app.set = function(k,v) end app.init = function() end -- load config app.opts = require('config')(app) app.runcmd(app) -- run clicmds -- init URL router app.url['^/data'] = '/data.lua' -- setup custom file endpoint app.url['^/$'] = '/page/index.lua' -- alias for app.tpl( LoadAsset('index.html'), app ) app.get('^/design[/]?$', util.pagerender('page/design.html')) app.url['^/admin[/]?$'] = '/page/admin/index.lua' app.post('^/save', function(req,res,next) -- setup inline POST endpoint -- also .get(), .put(), .delete(), .options() app.cache = req.body -- middleware auto-decodes json res.status(200) res.body({cache=app.cache}) -- middleware auto-encodes json next() end) app -- .use( require("middleware/httpauth")() ) .use( require("json").middleware() ) -- try plug'n'play json API middleware .use( app.router( app.url ) ) -- try url router .use( app.response() ) -- try serve app response (if any) .use( function(req,next) Route() end) -- fallback default redbean fileserver function OnHttpRequest() app.run() end app.on('init', function() if assert(unix.fork()) == 0 then os.execute("ls ; sleep 5") print("ok") --local ok, headers, body = Fetch('http://127.0.0.1:8080/test') end end) OnServerStart = function() app.init() -- this triggers init event end