Skip to content

chalaev/cl-webserver

Repository files navigation

chalaev.com

This is an example or template of a website powered by Hunchentoot web server. It was used for www.chalaev.com in the past, but as of 2022 www.chalaev.com is powered by the website builder.

This project was my first step to understand how one can use Common Lisp to run a real-life web server. My (closed-source) website builder grew out of this code.

Introduction

The following server features are tested:

  • serve static files and generated pages on GET request,
  • basic authentication,
  • customized error pages (e.g. 404.html),
  • serves index.html when asked for /, and page.html when asked for page (requires hunchentoot update).

Requirements

Usual linux environment, sbcl, quicklisp, emacs.

Two sbcl packages unavailable in quicklisp: cl-simple-logger and lisp goodies, unpacked into your local quicklisp repository:

tar xjf cl-shalaev.tbz --directory=$HOME/quicklisp/local-projects/
tar xjf simple-log.tbz --directory=$HOME/quicklisp/local-projects/

where it is assumed that your quicklisp is installed in ~/quicklisp/.

Compiling (or not?)

Compiling is unnecessary: we could just launch sbcl on the server and evaluate

(ql:quickload :web-server)
(web-server:start t)

However, I prefer to compile because compilation

  • makes the code faster,
  • saves valuable system resources on the server: e.g., we do not need to install sbcl there, and
  • makes it more difficult for intruders to analyze back end code on the server.

make compiles the code to a 16Mb binary file which is copied to the server and launched there. (Manual SBCL compilation with --with-sb-core-compression is required to shrink the binary size.)

You probably have to update Makefile configuration (specifying where your sbcl and quicklisp are installed) to make it work on your system.

Starting the server

Apart from code from this project we also need

  1. certbot to obtain our SSL-certificates, and
  2. nginx as a proxy.

The specific configuration file responsible for www.chalaev.com resides in /etc/nginx/sites-enabled/chalaev.com

Debugging

Swank allows to connect to the (remote) code and update it (or change variables’ values) without actually restarting the server. We will use port 4015 for slime connection:

ssh -L 4015:localhost:4005 -fN chalaev.com
ssh -O check chalaev.com

Then in local emacs we

M-x slime-connect
localhost
4015

After that, we just use slime for debugging, just as for locally running code, but feeling almost like debugging the Deep Space 1 spacecraft ☺.

License

This code is released under MIT license.

About

simple hunchentoot-powered website

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

 
 
 

Contributors