xrforge-v2/src/.init.lua

66 lines
2.1 KiB
Lua
Raw Normal View History

2026-07-21 19:19:52 +02:00
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"
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",
cache = {},
opts = {
title="My XRForge experiences",
subtitle="Portable XR experiences for PhoneVR, VRheadset, desktop & mobile."
},
cmd={
help = {file="help.lua", info="displays help cmds"},
server = {file="server.lua", info="starts the webserver"}
},
title = 'XRForge - local-first XR experiences',
subtitle = 'XRForge makes local-first XR easy',
notes = {'🤩 portable selfsovereign', '🖧 JanusXR / XR Fragments', '♻ decentralized'}
}
app.url['^/data'] = '/data.lua' -- setup custom file endpoint
app.url['^/$'] = '/index.lua' -- alias for app.tpl( LoadAsset('index.html'), app )
app.get('^/admin/$', app.template('admin/index.html') ) -- alias for app.tpl( LoadAsset('index.html'), app )
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("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('template', function(a,b,c,d,e)
print("TEMPLATE!")
end)
function OnHttpRequest() app.run() end
print("ja")
--function OnHttpRequest()
-- if( not dir.serve("./experiences") ) then
-- print("default")
-- Route()
-- end
--end
--