Skip to content

Commit

Permalink
fix: use PORT env variable to listen on port
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Hivert <[email protected]>
  • Loading branch information
ghivert committed May 14, 2024
1 parent 6d68abd commit 89e7998
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/backend/src/backend.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn main() {
router.handle_request(_, ctx)
|> wisp.mist_handler(secret_key_base)
|> mist.new()
|> mist.port(3000)
|> mist.port(cnf.port)
|> mist.start_http()

let assert Ok(_) =
Expand Down
9 changes: 7 additions & 2 deletions apps/backend/src/backend/config.gleam
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import gleam/erlang/os
import gleam/int
import gleam/pgo
import gleam/result
import wisp

pub type Context {
Context(db: pgo.Connection, hex_api_key: String)
}

pub type Config {
Config(database_url: String, hex_api_key: String)
Config(database_url: String, hex_api_key: String, port: Int)
}

pub fn read_config() {
let assert Ok(database_url) = os.get_env("DATABASE_URL")
let assert Ok(hex_api_key) = os.get_env("HEX_API_KEY")
Config(database_url, hex_api_key)
let assert Ok(port) =
os.get_env("PORT")
|> result.try(int.parse)
Config(database_url, hex_api_key, port)
}

pub fn get_secret_key_base() {
Expand Down

0 comments on commit 89e7998

Please sign in to comment.