Main problem here is, when serving *.js file:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
How do I add content-type to the HTTP.jl server ?
Existing code:
using HTTP
const HOST = "127.0.0.1"
const PORT = 8080
println("Server Started")
router_8080 = HTTP.Router();
router_8001 = HTTP.Router();
const www_root = "/voxel/www/"
function do_8080(r::HTTP.Request)
r.target == "/" && return HTTP.Response(200, read(www_root * "index.html"))
local path = www_root * sanitize_path(r.target);
return isfile(path) ? HTTP.Response(200, read(path)) : HTTP.Response(404)
end
function sanitize_path(s :: String)
local t = split(s, "/");
local t = filter(s -> s != "." && s != "..", t)
return join(t, "/")
end
function do_8001(::HTTP.Request)
return HTTP.Response(200, "Hello World 8001")
end
HTTP.register!(router_8080, "GET", "/", do_8080)
HTTP.register!(router_8080, "GET", "*", do_8080)
HTTP.register!(router_8001, "GET", "/", do_8001)
HTTP.register!(router_8001, "GET", "*", do_8001)
@async HTTP.serve(router_8080, "127.0.0.1", 8080)
HTTP.serve(router_8001, "127.0.0.1", 8001)