Gemenon.jl/Readme.org

50 lines
1.2 KiB
Org Mode
Raw Normal View History

2020-10-23 11:25:16 +02:00
#+title: Gemenon.jl -- A Gemini Server
* What is it
Gemenon.jl is a server for the [[https://gemini.circumlunar.space/][gemini]] protocol.
It's written in [[https://julialang.org/][Julia]].
* How to use
The usage is quite simple and similar to [[https://github.com/JuliaWeb/HTTP.jl][HTTP.jl]]
First, import the library
2020-11-01 21:09:36 +01:00
#+begin_src julia :tangle server.jl
2020-10-23 11:25:16 +02:00
using Gemenon
#+end_src
Then, setup the SSL config
2020-11-01 21:09:36 +01:00
#+begin_src julia :tangle server.jl
2020-10-30 22:31:18 +01:00
const verify_callback(preverify_ok, x509_ctx)::Cint = 1
2020-10-23 11:25:16 +02:00
2020-10-30 22:31:18 +01:00
function init_ssl_context()
ctx = Gemenon.OpenSSL.SSLContext()
Gemenon.OpenSSL.ca_chain!(ctx, "./cert.crt", "./key.key")
2020-10-23 11:25:16 +02:00
2020-10-30 22:31:18 +01:00
Gemenon.OpenSSL.set_options!(ctx, Gemenon.OpenSSL.SSL_OP_NO_SSLv3)
2020-10-23 11:25:16 +02:00
2020-10-30 22:31:18 +01:00
accept_all = @cfunction(verify_callback, Cint, (Cint, Ptr{Cvoid}))
Gemenon.OpenSSL.set_verify_mode(ctx, Gemenon.OpenSSL.VERIFY_PEER, accept_all)
ctx
end
2020-10-23 11:25:16 +02:00
#+end_src
2020-10-30 22:31:18 +01:00
You are ready to listen for connections!
You can do this like in Mux.jl
2020-10-23 11:25:16 +02:00
2020-11-01 21:09:36 +01:00
#+begin_src julia :tangle server.jl
2020-10-30 22:31:18 +01:00
@app test = (
req -> document(req.conn, """
2020-10-23 11:25:16 +02:00
# Welcome to Gemenon!
You can discuss about this on
2020-10-30 22:31:18 +01:00
=> gemini://nixo.xyz/ The Gemenon-Powered Anonymous Board
2020-10-23 11:25:16 +02:00
"""))
2020-10-30 22:31:18 +01:00
2020-11-01 19:20:04 +01:00
serve(test, init_ssl_context, Gemenon.Sockets.ip"0.0.0.0", 1965)
2020-10-23 11:25:16 +02:00
#+end_src