Skip to content

Commit

Permalink
fix: listen on PORT instead of 8080
Browse files Browse the repository at this point in the history
  • Loading branch information
yuaanlin committed Aug 11, 2024
1 parent 52c3251 commit cfbdfc3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/my_web_app.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import mist
import gleam/erlang/process
import gleam/bytes_builder
import gleam/http/response.{Response}
import gleam/erlang/os
import gleam/int

pub fn get_port() -> Int {
case os.get_env("PORT") {
Ok(value) -> case int.parse(value) {
Error(e) -> 8080
Ok(i) -> i
}
Error(_) -> 8080 // If the environment variable is not set, fallback to 8080
}
}

pub fn main() {
let assert Ok(_) =
web_service
|> mist.new
|> mist.port(8080)
|> mist.port(get_port())
|> mist.start_http
process.sleep_forever()
}
Expand Down

0 comments on commit cfbdfc3

Please sign in to comment.