Created
February 11, 2019 19:31
-
-
Save wookay/f72e791a5bc1b1def070435cebeba490 to your computer and use it in GitHub Desktop.
example.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using HTTP | |
using HTTP.Messages: setheader | |
using Sockets | |
index = HTTP.Handlers.RequestHandlerFunction() do req | |
resp = req.response | |
setheader(resp, "Access-Control-Allow-Origin" => "*") | |
resp.body = Vector{UInt8}("ok") | |
@info :resp resp | |
resp | |
end | |
run = HTTP.Handlers.RequestHandlerFunction() do req | |
resp = req.response | |
setheader(resp, "Access-Control-Allow-Origin" => "*") | |
resp.body = Vector{UInt8}("ok") | |
@info :resp resp | |
resp | |
end | |
r = HTTP.Router() | |
HTTP.@register(r, "GET", "/", index) | |
HTTP.@register(r, "POST", "/run", run) | |
port = 8080 | |
server = Sockets.listen(Sockets.InetAddr(parse(IPAddr, "127.0.0.1"), port)) | |
handler = req -> HTTP.handle(r, req) | |
tsk = @async HTTP.listen(handler, "127.0.0.1", port; server=server) | |
@info :tsk tsk | |
Base.JLOptions().isinteractive==0 && wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment