flight-journal/journal/08-08-2020-maj-cgi-support.gmi

57 lines
1.9 KiB
Plaintext
Raw Normal View History

2020-08-09 01:48:35 +00:00
# Maj CGI Support
I have just released Maj 0.6.0 which brings support for CGI[1] to the framework. This allows arbitrary other programs to run as handlers for Maj and confirms to the specification made by Jetforce[2].
=> https://tools.ietf.org/rfc/rfc3875.txt [1]: CGI
=> https://github.com/michael-lazar/jetforce [2]: Jetforce
For a few examples of this, see the following URLs:
=> /cgi-bin/env.sh
=> /cgi-bin/olinfetch.wasm
This also includes support for running programs written with WebAssembly using pa'i[3]. Here is the source code that powers olinfetch.wasm:
```
#![no_main]
#![feature(start)]
extern crate olin;
use anyhow::{anyhow, Result};
use olin::{entrypoint, env, runtime, stdio, time};
use std::io::Write;
entrypoint!();
fn main() -> Result<()> {
let mut out = stdio::out();
if let Ok(url) = env::get("GEMINI_URL") {
write!(out, "20 text/gemini\n# WebAssembly Runtime Information\n")?;
write!(out, "URL: {}\n", url)?;
write!(
out,
"Server software: {}\n",
env::get("SERVER_SOFTWARE").unwrap()
)?;
}
let mut rt_name = [0u8; 32];
let runtime_name = runtime::name_buf(rt_name.as_mut())
.ok_or_else(|| anyhow!("Runtime name larger than 32 byte limit"))?;
write!(out, "CPU: {}\n", "wasm32").expect("write to work");
write!(
out,
"Runtime: {} {}.{}\n",
runtime_name,
runtime::spec_major(),
runtime::spec_minor()
)?;
write!(out, "Now: {}\n", time::now().to_rfc3339())?;
Ok(())
}
```
This allows users to write custom behavior in any language that can compile to WebAssembly. This will also allow this custom behavior to be moved across machines to any CPU or operating system that can run the WebAssembly runtime. This allows trivial mobility between processor types, allowing users to not be beholden to individual vendors or operating systems.