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" package.path = package.path .. ";plugin/?.lua" util = require "util" json = require "json" -- special script called by main redbean process at startup HidePath('/usr/share/zoneinfo/') HidePath('/usr/share/ssl/') -- create app = require("soakbean") { bin = "./xrforge.com", bindir = arg[-1]:gsub("xrforge.com",""), cache = { items = {} }, plugin = {}, opts = {}, cmd={ help = {file="cmd/help.lua", info="display all possible flags"}, server = {file="cmd/server.lua", info="starts the webserver"}, createplugin = {file="cmd/createplugin.lua", info="generates skeleton plugin"}, generate = {file="cmd/generate.lua", info="generate www-folder with XR experiences"}, test = {file="cmd/test.lua", info="run testsuite (selftest)"} } } -- 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) -- load system plugins app.plugin.moderation = require('plugin/moderation') app.plugin.diskscan = require('plugin/diskscan') app.plugin.manyfold = require('plugin/manyfold') app.plugin.janusxr = require('plugin/janusxr') -- ensure plugin config-defaults foreach( app.plugin, function(name,plugin) foreach( plugin.opts, function(k,opt) local key = opt.key:gsub("app.opts.","") if not app.opts[ key ] then app.opts[ key ] = opt.default end end) end) -- set order preference (optional) app.plugin[1] = app.plugin.diskscan app.plugin[2] = app.plugin.moderation app.plugin[3] = app.plugin.janusxr app.plugin[4] = app.plugin.manyfold app.runcmd(app) -- run clicmds print = function(...) Log(kLogInfo, ... or "''") end -- nice redbean logging from now on -- init URL router app.url['^/data'] = '/data.lua' -- setup custom file endpoint app.url['^/$'] = '/page/index.lua' app.url['^/experiences[/]?$'] = '/page/experiences.lua' app.url['^/admin[/]?$'] = '/page/admin/index.lua' app.get('^/design[/]?$', util.pagerender('page/design.html')) app.get('^/about[/]?$', util.pagerender('page/about.html')) 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 app.on('init', function() if assert(unix.fork()) == 0 then app.plugin.diskscan.scan(app.opts.plugin_diskscan_dir) print_r(app.cache) --os.execute("ls ; sleep 5") print("ok") --local ok, headers, body = Fetch('http://127.0.0.1:8080/test') end end) function OnHttpRequest() app.run() end OnServerStart = function() app.init() -- this triggers init event end