Hacking a Gemini web frontend
2020-05-26
I created a basic gateway for Gemini <-> HTTP world.
This page is reachable via https since about some minutes. I've hacked together a small web server based on two Lua modules:
- http
- luasocket
With these modules, it's easy to write a small web server that provides a http interface. As text/gemini is a really simple file format, writing a parser and HTML renderer took me about half an hour of work, with an additional half hour to fix several bugs in the newline rendering.
Note to self: Lua 5.1 is not Lua 5.3 and has some minor differences in pattern matching and such features.
Using nginx, you can easily integrate your own little servers behind some "strong and mature" project with HTTPS serving, virtual hosts and all of that. It only requires this small proxy_pass configuraton:
# /etc/nginx/sites/random-projects server { # Listen on both IPv4 and IPv6 listen 443 ssl; listen [::]:443 ssl; server_name random-projects.net; # Enable SSL/TLS ssl on; # This is required to serve index.gemini, otherwise no index files are used. index index.gemini; location / { # This passes the HTTPS request to the Lua script proxy_pass http://127.0.0.1:1865; } }
The Lua server itself runs as a systemd unit and requires some patches in the Environment to find the libraries used:
[Unit] Description=Gemini-Web Bridge After=network.target [Service] Type=simple WorkingDirectory=/home/felix/gemini-web-bridge ExecStart=/usr/bin/lua /home/felix/gemini-web-bridge/main.lua Restart=always User=felix Group=users # These two env variables must be set for Lua to find our packages with require "X" Environment=LUA_PATH=/foo/bar/?.lua;/foo/bar/?/init.lua Environment=LUA_CPATH= [Install] WantedBy=multi-user.target