💾 Archived View for rwv.io › 2020-11-13.gmi captured on 2022-03-01 at 16:01:49. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-11-30)

➡️ Next capture (2023-01-29)

-=-=-=-=-=-=-

Racket and gemini are awesome together

Just spend an hour playing with racket (my first) to see if I can get a gemini server up and running. I can! It's awesome!

https://racket-lang.org/

This is all it takes:

#lang racket

(require racket/string)
(require racket/port)
(require net/url-string)
(require openssl)

(define root-path "root")

(define (url-path->string p)
  (string-join (map path/param-path p) "/"))

(define listener
  (let ((listener (ssl-listen 1965)))
    (ssl-load-certificate-chain! listener "localhost.cert.pem")
    (ssl-load-private-key! listener "localhost.key.pem" #f)
    listener))

(let loop ()
  (let-values ([(in out) (ssl-accept listener)])
    (let* ((url (string->url (string-trim (read-line in))))
           (path (url-path->string (url-path url))))
      (ssl-abandon-port in)

      (display "20 text/gemini\r\n" out)
      (let ((in (open-input-file (build-path root-path path) )))
         (copy-port in out)
         (close-input-port in)))

    (ssl-abandon-port out))
  (loop))

It only responds with "20", expects everything to be gemini text and crashes when the requested file does not exists. Not yet ready for "production" but that's plenty for a language I never used. Initial commit, done.

Cheers,

R.

--

📅 2020-11-13

🏷 gemini, racket, programming

📧 hello@rwv.io

🅭 BY-NC-SA 4.0