Tabla de Contenidos
Algernon
Servidor web auto-contenido escrito en Go, diseñado para ser ligero, versátil y fácil de desplegar.
Características
Algernon es un servidor web que incluye soporte integrado para:
- Lenguajes y tecnologías: Lua, Teal (Lua tipado), Markdown, JSX, Amber, Pongo2, Sass (SCSS), GCSS.
- Bases de datos: BoltDB (embebido), Redis, PostgreSQL, MySQL, SQLite, MSSQL.
- Protocolos: HTTP/2, QUIC, HTTP/S.
- Otras características:
- Plugins
- Gestión de usuarios y permisos
- Auto-refresh para desarrollo (Linux/macOS)
- Integración con Ollama para modelos de lenguaje (LLMs)
Todo esto está empaquetado en un único ejecutable, lo que facilita su uso sin necesidad de instalar múltiples dependencias.
Instalación
Realmente no necesita instalación porque se trata de un único fichero ejecutable.
Docker
Si creamos un directorio llamado localhost creamos un fichero index.md (con texto con sintaxis Markdown) y luego ejecutamos lo siguiente:
docker run -it -p4000:4000 -v .:/srv/algernon xyproto/algernon
Cuando accedamos a http://localhost:4000 veremos el contenido de index.md interpretado como HTML.
También podemos crear un Docker Compose:
--- services: algernon: image: xyproto/algernon:latest container_name: algernon ports: - 3000:3000 volumes: - ./www:/srv/algernon entrypoint: ["/bin/algernon", "--dev", "--autorefresh", "--dir", "/srv/algernon", "--httponly", "--server"] restart: unless-stopped
Tras ejecutarlo, podremos ir a http://localhost:3000 y veremos el contenido del directorio www.
Uso
Ejemplo más sencillo sirviendo el directorio en el que se encuentra el ejecutable de Algernon:
algernon -x .
Ejecutará el servidor web en el puerto 3000 (por defecto).
Si queremos habilitar la recarga automática cuando hay cambios:
algernon -a .
Opciones
A continuación se muestra la sintaxos del ejecutable de Algernon y las diferentes opciones que admite como argumentos:
Algernon 1.17.4
Web Server
Syntax:
algernon [flags] [file or directory to serve] [host][:port]
Available flags:
-a, --autorefresh Enable event server and auto-refresh feature.
Sets cache mode to "images".
-b, --bolt Use "/tmp/algernon.db"
for the Bolt database.
-c, --statcache Speed up responses by caching os.Stat.
Only use if served files will not be removed.
-d, --debug Enable debug mode (show errors in the browser).
-e, --dev Development mode: Enables Debug mode, uses
regular HTTP, Bolt and sets cache mode "dev".
-h, --help This help text
-l, --lua Don't serve anything, just present the Lua REPL.
-m View the given Markdown file in the browser.
Quits after the file has been served once.
("-m" is equivalent to "-q -o -z").
-n, --nobanner Don't display a colorful banner at start.
-o, --open=EXECUTABLE Open the served URL in a browser with a standard
methodor or with the given (optional) executable.
-p, --prod Serve HTTP/2+HTTPS on port 443. Serve regular
HTTP on port 80. Uses /srv/algernon for files.
Disables debug mode. Disables auto-refresh.
Enables server mode. Sets cache to "prod".
-q, --quiet Don't output anything to stdout or stderr.
-r, --redirect Redirect HTTP traffic to HTTPS, if both are enabled.
-s, --server Server mode (disable debug + interactive mode).
-t, --httponly Serve regular HTTP.
-u Serve over QUIC / HTTP3.
-v, --version Application name and version
-V, --verbose Slightly more verbose logging.
-z, --quit Quit after the first request has been served.
--accesslog=FILENAME Access log filename. Logged in Combined Log Format (CLF).
--addr=[HOST][:PORT] Server host and port (":3000" is default)
--boltdb=FILENAME Use a specific file for the Bolt database
--cache=MODE Sets a cache mode. The default is "on".
"on" - Cache everything.
"dev" - Everything, except Amber,
Lua, GCSS, Markdown and JSX.
"prod" - Everything, except Amber and Lua.
"small" - Like "prod", but only files <= 64KB.
"images" - Only images (png, jpg, gif, svg).
"off" - Disable caching.
--cachesize=N Set the total cache size, in bytes.
--cert=FILENAME TLS certificate, if using HTTPS.
--conf=FILENAME Lua script with additional configuration.
--clear Clear the default URI prefixes that are used
when handling permissions.
--cookiesecret=STRING Secret that will be used for login cookies.
--ctrld Press ctrl-d twice to exit the REPL.
--dbindex=INDEX Redis database index (0 is default).
--dir=DIRECTORY Set the server directory
--domain Serve files from the subdirectory with the same
name as the requested domain.
--eventrefresh=DURATION How often the event server should refresh
(the default is "350ms").
--eventserver=[HOST][:PORT] SSE server address (for filesystem changes).
--http2only Serve HTTP/2, without HTTPS.
--internal=FILENAME Internal log file (can be a bit verbose).
--key=FILENAME TLS key, if using HTTPS.
--largesize=N Threshold for not reading static files into memory, in bytes.
--letsencrypt Use certificates provided by Let's Encrypt for all served
domains and serve over regular HTTPS by using CertMagic.
--limit=N Limit clients to N requests per second
(the default is 10).
--log=FILENAME Log to a file instead of to the console.
--maria=DSN Use the given MariaDB or MySQL host/database.
--mariadb=NAME Use the given MariaDB or MySQL database name.
--ncsa=FILENAME Alternative access log filename. Logged in Common Log Format (NCSA).
--nocache Another way to disable the caching.
--nodb No database backend. (same as --boltdb=/dev/null).
--noheaders Don't use the security-related HTTP headers.
--nolimit Disable rate limiting.
--postgres=DSN Use the given PostgreSQL host/database.
--postgresdb=NAME Use the given PostgreSQL database name.
--sqlite=FILENAME Use the given SQLite file (ie. "sqlite.db&cache=shared&mode=memory").
--redis=[HOST][:PORT] Use ":6379" for the Redis database.
--rawcache Disable cache compression.
--servername=STRING Custom HTTP header value for the Server field.
--stricter Stricter HTTP headers (same origin policy).
--theme=NAME Builtin theme to use for Markdown, error pages,
directory listings and HyperApp apps.
Possible values are: light, dark, bw, redbox, wing,
material, neon, werc or setconf.
--timeout=N Timeout when serving files, in seconds.
--watchdir=DIRECTORY Enables auto-refresh for only this directory.
-x, --simple Serve as regular HTTP, enable server mode and
disable all features that requires a database.
Example usage:
For auto-refreshing a webpage while developing:
algernon --dev --httponly --debug --autorefresh --bolt --server . :4000
Serve /srv/mydomain.com and /srv/otherweb.com over HTTP and HTTPS + HTTP/2:
algernon -c --domain --server --cachesize 67108864 --prod /srv
Serve the current dir over QUIC, port 7000, no banner:
algernon -s -u -n . :7000
Serve the current directory over HTTP, port 3000. No limits, cache,
permissions or database connections:
algernon -x

