Skip to content

Commit cfbdfc3

Browse files
author
Yuanlin Lin
committed
fix: listen on PORT instead of 8080
1 parent 52c3251 commit cfbdfc3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/my_web_app.gleam

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@ import mist
22
import gleam/erlang/process
33
import gleam/bytes_builder
44
import gleam/http/response.{Response}
5+
import gleam/erlang/os
6+
import gleam/int
7+
8+
pub fn get_port() -> Int {
9+
case os.get_env("PORT") {
10+
Ok(value) -> case int.parse(value) {
11+
Error(e) -> 8080
12+
Ok(i) -> i
13+
}
14+
Error(_) -> 8080 // If the environment variable is not set, fallback to 8080
15+
}
16+
}
517

618
pub fn main() {
719
let assert Ok(_) =
820
web_service
921
|> mist.new
10-
|> mist.port(8080)
22+
|> mist.port(get_port())
1123
|> mist.start_http
1224
process.sleep_forever()
1325
}

0 commit comments

Comments
 (0)