-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenie.jl
35 lines (24 loc) · 834 Bytes
/
genie.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
haskey(ENV, "GENIE_ENV") || (ENV["GENIE_ENV"] = "dev")
if !haskey(ENV, "HOST")
ENV["HOST"] = (ENV["GENIE_ENV"] == "dev") ? "127.0.0.1" : "0.0.0.0"
end
### EARLY BIND TO PORT FOR HOSTS WITH TIMEOUT ###
import Sockets
const EARLYBINDING = if haskey(ENV, "EARLYBIND") && lowercase(ENV["EARLYBIND"]) == "true" && haskey(ENV, "PORT")
printstyled("\nEarly binding to host $(ENV["HOST"]) and port $(ENV["PORT"]) \n", color = :light_blue, bold = true)
try
Sockets.listen(parse(Sockets.IPAddr, ENV["HOST"]), parse(Int, ENV["PORT"]))
catch ex
@show ex
printstyled("\nFailed early binding!\n", color = :red, bold = true)
nothing
end
else
nothing
end
### OFF WE GO! ###
using Genie
const ROOT_PATH = pwd()
push!(LOAD_PATH, ROOT_PATH, "src")
Genie.load(context = @__MODULE__)
Genie.run(server = EARLYBINDING)