View Source Spaceboy.Server (Spaceboy v0.3.2)

Main configuration for your Spaceboy server. Roughly equivalent to Phoenix.Endpoint

TLS certificate and configuration

Server requires TLS certificate to function properly. It can be self-signed and you can generate one with this command:

mix spaceboy.gen.cert

The default location for certificate is: priv/ssl/ but you can change it to whatever path you want via configuration:

config :example, Example.Server,
  port: 1965,
  allowed_hosts: [],
  certfile: "priv/ssl/cert.pem",
  keyfile: "priv/ssl/key.pem"

or when starting your server in Application module (in case you need programmatically controlled configuration):

def start(_type, _args) do
  config = [
    port: 1965,
    allowed_hosts: [],
    certfile: "priv/ssl/cert.pem",
    keyfile: "priv/ssl/key.pem"
  ]

  children = [
    {Example.Server, config}
  ]

  Supervisor.start_link(children, strategy: :one_for_one, name: Example.Supervisor)
end

Other options

  • :port port on which the server listens on.
  • :allowed_hosts this option dictates which hosts the server considers valid. By default it is empty list which means the check is skipped and any host is considered valid but if you want to limit which hosts are allowed you do that here.

Gemini MIME type

To save yourself from always passing Gemini mime type when sending file it is recommended to add Gemini mime type to MIME library configuration:

config :mime, :types, %{
  "text/gemini" => ["gmi", "gemini"]
}

and you need to recompile MIME library: mix deps.clean mime --build

Summary

Functions

Add middleware to your server configuration

Functions

middleware(module, opts \\ [])

(macro)

Add middleware to your server configuration