82 lines
2.6 KiB
Lua
82 lines
2.6 KiB
Lua
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"
|
|
|
|
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/')
|
|
|
|
-- 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"}
|
|
}
|
|
}
|
|
|
|
-- api skeleton (implemented via soakbean's app.on(...))
|
|
app.set = function(k,v) end
|
|
app.init = function() end
|
|
app.scan = require('scan').scan
|
|
|
|
-- load config
|
|
app.opts = require('config')(app)
|
|
|
|
-- load plugins
|
|
app.plugin.janusxr = require('plugin/janusxr')
|
|
|
|
app.runcmd(app) -- run clicmds
|
|
|
|
-- 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
|
|
--os.execute("ls ; sleep 5")
|
|
app.scan()
|
|
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
|