From 673f38246ac3548caefec41183e3dd7477d9f6f6 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 13 Sep 2022 23:50:12 +0200 Subject: treewide: separate Lua runtime resources Move classes required for Lua runtime support into a new `luci-lua-runtime` package. Also replace the `luci.http` and `luci.util` classes in `luci-lib-base` with stubbed versions interacting with the ucode based runtime environment. Finally merge `luci-base-ucode` into the remainders of `luci-base`. Signed-off-by: Jo-Philipp Wich --- modules/luci-base/htdocs/cgi-bin/luci | 46 +++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'modules/luci-base/htdocs/cgi-bin') diff --git a/modules/luci-base/htdocs/cgi-bin/luci b/modules/luci-base/htdocs/cgi-bin/luci index c5c9847346..442e427d41 100755 --- a/modules/luci-base/htdocs/cgi-bin/luci +++ b/modules/luci-base/htdocs/cgi-bin/luci @@ -1,5 +1,41 @@ -#!/usr/bin/lua -require "luci.cacheloader" -require "luci.sgi.cgi" -luci.dispatcher.indexcache = "/tmp/luci-indexcache" -luci.sgi.cgi.run() +#!/usr/bin/env ucode + +'use strict'; + +import { stdin, stdout } from 'fs'; + +import dispatch from 'luci.dispatcher'; +import request from 'luci.http'; + +const input_bufsize = 4096; +let input_available = +getenv('CONTENT_LENGTH') || 0; + +function read(len) { + if (input_available == 0) { + stdin.close(); + + return null; + } + + let chunk = stdin.read(min(input_available, len ?? input_bufsize, input_bufsize)); + + if (chunk == null) { + input_available = 0; + stdin.close(); + } + else { + input_available -= length(chunk); + } + + return chunk; +} + +function write(data) { + return stdout.write(data); +} + +let req = request(getenv(), read, write); + +dispatch(req); + +req.close(); -- cgit v1.2.3