Redbean 2.0 is a platform for web applications packaged in a universal executable ZIP archive

A release of the Redbean 2.0 project is presented, offering a web server that allows web applications to be delivered in the form of a universal executable that can be run on Linux, Windows, MacOS, FreeBSD, NetBSD, and OpenBSD. All resources associated with the web application and the server are compiled into a single executable file that is compatible with the ZIP archive format and allows you to use the zip utility to add additional files. The ability to run one file in different operating systems and recognize it as a ZIP archive is achieved by manipulating the headers of executable files and linking to the multiplatform standard C library Cosmopolitan. The project code is distributed under the ISC license.

The idea of ​​the project is to supply a single executable file "redbean.com" with a built-in web server. A web application developer can use the zip utility to add HTML and Lua files to this file and get a self-sufficient web application that runs on all popular operating systems and does not require a separate web server to run on the system.

After launching the resulting executable file, the built-in web server is used to access the web application stored in the file. By default, the handler is attached to localhost, but the server can also be used as a regular public web server (for example, this server serves the project site). The embedded Web server supports HTTPS access and can be run using sandbox isolation to control which system interfaces are accessed. To control the operation of the server during its execution, an interactive REPL interface is provided (based on Lua REPL and the bestline library, an analogue of GNU Readline), which makes it possible to change the state of the process in interactive mode.

The web server is said to be capable of handling over a million requests per second on a typical PC, serving up gzip-compressed content. The good thing about performance is that zip and gzip use a common format, so data is served without recompressing from already compressed areas in the zip file. Also, because the executable is statically linked and is small, calling fork on it has little to no memory overhead.

In addition to processing static web content and executing JavaScript in the browser, web application logic can be extended using Lua scripting, the Fullmoon web framework, and the SQLite DBMS. Additional features include support for the argon2 password hashing scheme, the ability to determine the IP region using the MaxMind database, and access to the Unix API of the Cosmopolitan library. The base stack, which includes the web server, MbedTLS, Cosmopolitan, Lua, and SQLite, is only 1.9 MB.

A universal executable file is formed by combining segments and headers specific to different operating systems (PE, ELF, MACHO, OPENBSD, ZIP) in one file. To ensure that a single executable file runs on Windows and Unix systems, a trick is used, the essence of which is to encode Windows PE files as a shell script, taking advantage of the fact that Thompson Shell does not use the "#!" script marker. As a result, an executable file is created, which combines several different formats used in Linux, BSD, Windows and macOS. $ curl https://redbean.dev/redbean-demo-2.0.7.com >redbean.com $ chmod +x redbean.com $ zip redbean.com hello.html $ zip redbean.com hello.lua $ ./redbean .com -vv I2022-06-23T08:27:14+000767:redbean] (srvr) listen http://127.0.0.1:8080 >: waiting for command… $ curl https://127.0.0.1:8080/hello .html hello $ printf 'GET /hello.lua\n\n' | nc 127.0.0.1 8080 hello



Source: opennet.ru

Add a comment