-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws_run.jl
executable file
·43 lines (32 loc) · 1.11 KB
/
ws_run.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
36
37
38
39
40
41
42
43
#!/usr/bin/env julia --project=@.
doc = """Web service starter
Usage:
$(Base.basename(@__FILE__)) [--port=<num>] [--base_url=<url>] [--bind=<ip>]
Options:
-h --help Show this screen
-p, --port=<num> Port [default: 3333]
-b, --bind=<ip> Bind address [default: 0.0.0.0]
--base_url=<url> Additional URL prefix for the service [default: /]
"""
using DocOpt # import docopt function
using Pkg
args = docopt(doc, version = Pkg.project().version)
#@info args
using Sockets
function get_env_or(name::String, or_value)
if haskey(ENV, name)
@info("Using ENV $(name) value: $(ENV[name])")
ENV[name]
else
or_value
end
end
BASE_URL = get_env_or("BASE_URL", args["--base_url"])
HOST = Sockets.getaddrinfo(get_env_or("HOST", args["--bind"]))
PORT = parse(Int, get_env_or("PORT", args["--port"]))
app_server = Pkg.project().name
@info "Activating web service..."
@eval using $(Symbol(app_server))
m = getfield(Main, Symbol(app_server))
# endswith(PROGRAM_FILE, basename(@__FILE__)) && start_server()
m.AppServer.run_server(host = string(HOST), port = PORT, base_url = BASE_URL)