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

The release of the Redbean 2.0 project has been introduced, offering a web server that allows the delivery of web applications in the form of a universal executable file, which can be run on Linux, Windows, macOS, FreeBSD, NetBSD, and OpenBSD. All resources related to the web application and server are compiled into a single executable file, which is compatible with ZIP archive format and allows the use of the zip utility to add additional files. The ability to run a single file on different operating systems and recognize it as a ZIP archive is achieved through manipulations with the headers of executable files and linking with the cross-platform standard C library Cosmopolitan. The project's code is distributed under the ISC license.

The idea of the project is to provide a single executable file 'redbean.com' with a built-in web server. The web application developer can use the zip utility to add HTML and Lua files to this file, resulting in a standalone web application that runs on all popular operating systems and does not require a separate web server to be launched in the system.

Once the generated executable file is launched, the built-in web server is used to access the web application saved 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 hosts the project's website). The built-in web server supports HTTPS access and can operate using sandbox isolation, allowing control over which system interfaces are accessed. An interactive REPL interface (based on Lua REPL and the bestline library, a counterpart to GNU Readline) is provided to manage server operations during execution, enabling real-time process state changes.

It is claimed that the web server can handle more than a million requests per second on a standard PC, delivering content compressed with the gzip method. Its high performance is facilitated by the fact that zip and gzip use a common format, allowing data to be served without repacking from already compressed areas in the zip file. Additionally, since the executable file is created using static linking and has a small size, calling the fork function incurs almost no overhead when placed in memory.

In addition to processing static web content and executing JavaScript in the browser, the logic of a web application can be extended through scripts in Lua, the Fullmoon web framework, and the SQLite database. Notable 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 via the Cosmopolitan library. The size of the base stack, which includes the web server, MbedTLS, Cosmopolitan, Lua, and SQLite, is only 1.9 MB.

The universal executable is formed by merging segments and headers specific to different operating systems (PE, ELF, MACHO, OPENBSD, ZIP) into a single file. A trick is used to ensure that a single executable file can run on both Windows and Unix systems, which involves encoding Windows PE files as a shell script, utilizing the fact that the Thompson Shell does not use the script marker '#!'. As a result, an executable file is created, combining 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
Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster