From 5ab60007dacfc51850ce093683fa559a39a6eb44 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Sat, 31 Dec 2022 11:45:06 +0300 Subject: [PATCH] make the listen path fully costumizable --- .env.example | 3 ++- config.toml.example | 3 ++- src/crystal-gauntlet.cr | 13 +++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index bd18a4a..bf24cd6 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ DATABASE_URL=sqlite3://./crystalgauntlet.db -PORT=8080 \ No newline at end of file +# can either be http:// or unix:// for a unix socket +LISTEN_ON=http://127.0.0.1:8080 \ No newline at end of file diff --git a/config.toml.example b/config.toml.example index 416bf50..6691d94 100644 --- a/config.toml.example +++ b/config.toml.example @@ -7,7 +7,8 @@ # # example: # boomlings.com/database/ -# exampke.com/aaaaaaaaaa/ +# example.com/aaaaaaaaaa/ +# ^^^^^^^^^^^ # # leaving blank will disable this append_path = "" diff --git a/src/crystal-gauntlet.cr b/src/crystal-gauntlet.cr index 17f322f..29cd383 100644 --- a/src/crystal-gauntlet.cr +++ b/src/crystal-gauntlet.cr @@ -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