make the listen path fully costumizable

This commit is contained in:
Jill 2022-12-31 11:45:06 +03:00
parent 2b3f36f6ea
commit 5ab60007da
3 changed files with 15 additions and 4 deletions

View File

@ -1,2 +1,3 @@
DATABASE_URL=sqlite3://./crystalgauntlet.db
PORT=8080
# can either be http:// or unix:// for a unix socket
LISTEN_ON=http://127.0.0.1:8080

View File

@ -7,7 +7,8 @@
#
# example:
# boomlings.com/database/
# exampke.com/aaaaaaaaaa/
# example.com/aaaaaaaaaa/
# ^^^^^^^^^^^
#
# leaving blank will disable this
append_path = ""

View File

@ -62,8 +62,17 @@ module CrystalGauntlet
end
end
puts "Listening on http://127.0.0.1:8080"
server.listen(8080)
listen_on = URI.parse(ENV["LISTEN_ON"]? || "http://localhost:8080").normalize
case listen_on.scheme
when "http"
server.bind_tcp(listen_on.hostname.not_nil!, listen_on.port.not_nil!)
when "unix"
server.bind_unix(listen_on.to_s.sub("unix://",""))
end
puts "Listening on #{listen_on.to_s}"
server.listen
end
end