diff --git a/.env b/.env index d085537..1afc1dd 100644 --- a/.env +++ b/.env @@ -1,7 +1,8 @@ # aliases build(){ $(pwd)/util/xrforge.sh build; } +rebuild(){ $(pwd)/util/xrforge.sh rebuild; } -# server hook +# forgejo server hook #test "$GITEA_ROOT_URL" = "https://xrforge.isvery.ninja/" && { # cp -r example/assets/* . #} diff --git a/.gitignore b/.gitignore index 425ba6d..3377cf3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -experiences +experienceA +experienceB result +src/v +janusweb* diff --git a/README.md b/README.md index d65ff7b..19848b7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,3 @@ - -``` -$ source .env # not needed if your system has autoenv -$ util/xrforge.sh build # fast: repeatable build -$ nix-build # slow: reproducable nix build (for experts) -``` - NOTES: ``` @@ -44,6 +37,21 @@ curl -L -X 'GET' 'http://xrforge.isvery.ninja/models?page=1&order=name' -H curl -L -X 'GET' 'http://xrforge.isvery.ninja/models?page=1&order=recent' -H 'accept: application/vnd.manyfold.v0+json' ``` +## Developing + +```bash +$ source .env # not needed if your system has autoenv +$ build # fast: repeatable build +$ rebuild # faster: lua-repeatable build +$ nix-build # slow: reproducable nix build (for experts) +``` + +Then run with debug flag to see output of `trace()` calls +```bash +$ DEBUG=1 result/bin/xrforge.com +``` + + ## Permacomputing Spirit * developed on [Dillo](https://dillo-browser.github.io/) as lowest common denominator / compatibility diff --git a/src/.args b/src/.args index 2d471fe..fcc4b4b 100644 --- a/src/.args +++ b/src/.args @@ -1,8 +1,8 @@ -H -"Access-Control-Allow-Origin: *" +Access-Control-Allow-Origin: * -H -"Access-Control-Allow-Method: GET, POST, OPTIONS" +Access-Control-Allow-Method: GET, POST, OPTIONS -H -"Allow: GET, POST, OPTIONS" +Allow: GET, POST, OPTIONS -D . diff --git a/src/.init.lua b/src/.init.lua index ee6fe90..f53711b 100644 --- a/src/.init.lua +++ b/src/.init.lua @@ -2,6 +2,7 @@ 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 @@ -12,27 +13,30 @@ json = require "json" 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 = {}, + cache = { items = {} }, + plugin = {}, opts = {}, cmd={ - help = {file="cmd/help.lua", info="display all possible flags"}, - server = {file="cmd/server.lua", info="starts the webserver"} + 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 @@ -62,16 +66,17 @@ app -- .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") + --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 diff --git a/src/.lua/config.lua b/src/.lua/config.lua index 56fb305..63c9f53 100644 --- a/src/.lua/config.lua +++ b/src/.lua/config.lua @@ -36,7 +36,23 @@ return function(app) if k == 'app.opts' then app.opts = v app.opts.updated = os.time() - local newconfig = "app.on('init', function()\n\tprint('config loaded')\nend)\n\nreturn " .. util.dump(app.opts) + local newconfig = [[ + +-- TIP: run 'xrforge.com createplugin' to start writing plugins + +app.on('init', function() + print('config loaded') + + local scan = app.scan + app.scan = function() + os.execute("echo scan before-hook") + scan() + os.execute("echo scan after-hook") + end + +end) + + ]] .. "\n\nreturn " .. util.dump(app.opts) newconfig = newconfig:gsub("^}$"," init = function() print('xrforge.lua config loaded') end\n}") util.writefile( app.bindir .. configfile, newconfig ) print("stored xrforge.lua") diff --git a/src/.lua/opendirectory.lua b/src/.lua/opendirectory.lua index d56ca98..4f121c2 100644 --- a/src/.lua/opendirectory.lua +++ b/src/.lua/opendirectory.lua @@ -46,9 +46,10 @@ dir.foreach = function(path,cb) if name == "." then goto continue end attr,err = unix.stat(path..'/'..name, unix.AT_SYMLINK_NOFOLLOW) if err then print("error: ".. name .. ": " ..err) end - cb(path,stat,state,name,kind,ino,off,attr) + cb(path,stat,state,name,kind,ino,off,attr, path .. "/" ..name) ::continue:: end + return state end dir.serve = function(folder) -- raw redbean function (use dir.foreach in soakbean) @@ -97,7 +98,7 @@ dir.serve = function(folder) -- raw redbean function (use dir.foreach in soakbea Write('
\r\n') local stat, state = dir.scan(path) - dir.foreach(path, function(path,stat,state,name,kind,ino,off,attr) + dir.foreach(path, function(path,stat,state,name,kind,ino,off,attr,fullpath) Write('| + | + | + |
|---|---|---|
| + | + | ${plugin.info} |
+