Skip to content

Commit 454e63c

Browse files
committed
rolling back
1 parent eabd67f commit 454e63c

File tree

1 file changed

+59
-72
lines changed

1 file changed

+59
-72
lines changed

src/server.jl

Lines changed: 59 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -606,86 +606,73 @@ current directory. (See also [`example`](@ref) for an example folder).
606606
# starts the file watcher
607607
start(fw)
608608

609-
# HTTP uses LoggingExtras and, in particular, a @logmsgv which is very
610-
# annoying for LiveServer, see https://github.com/JuliaWeb/HTTP.jl/issues/938
611-
# as a result we just capture all the logging and discard everything
612-
Base.CoreLogging.with_logger(TestLogger()) do
613-
614-
# make request handler
615-
req_handler = HTTP.Handlers.streamhandler() do req
616-
req = preprocess_request(req)
617-
serve_file(
618-
fw, req;
619-
inject_browser_reload_script = inject_browser_reload_script,
620-
allow_cors = allow_cors
621-
)
622-
end
623-
624-
server, port = get_server(host, port, req_handler)
625-
host_str = ifelse(host == string(Sockets.localhost), "localhost", host)
626-
url = "http://$host_str:$port"
627-
println(
628-
"✓ LiveServer listening on $url/ ...\n (use CTRL+C to shut down)"
609+
# make request handler
610+
req_handler = HTTP.Handlers.streamhandler() do req
611+
req = preprocess_request(req)
612+
serve_file(
613+
fw, req;
614+
inject_browser_reload_script = inject_browser_reload_script,
615+
allow_cors = allow_cors
629616
)
617+
end
630618

631-
launch_browser && open_in_default_browser(url)
632-
# wait until user interrupts the LiveServer (using CTRL+C).
633-
try
634-
counter = 1
635-
while true
636-
if WS_INTERRUPT[] || fw.status == :interrupted
637-
# rethrow the interruption (which may have happened during
638-
# the websocket handling or during the file watching)
639-
throw(InterruptException())
640-
end
641-
642-
sleep(2)
643-
try
644-
sqrt(-1)
645-
catch e
646-
HTTP.LoggingExtras.@logmsgv 1 HTTP.Logging.Error "I don't want to see this" exception=(e, stacktrace(catch_backtrace()))
647-
end
648-
649-
# run the auxiliary function if there is one (by default this does
650-
# nothing)
651-
coreloopfun(counter, fw)
652-
# update the cycle counter and sleep (yields to other threads)
653-
counter += 1
654-
sleep(0.1)
619+
server, port = get_server(host, port, req_handler)
620+
host_str = ifelse(host == string(Sockets.localhost), "localhost", host)
621+
url = "http://$host_str:$port"
622+
println(
623+
"✓ LiveServer listening on $url/ ...\n (use CTRL+C to shut down)"
624+
)
625+
626+
launch_browser && open_in_default_browser(url)
627+
# wait until user interrupts the LiveServer (using CTRL+C).
628+
try
629+
counter = 1
630+
while true
631+
if WS_INTERRUPT[] || fw.status == :interrupted
632+
# rethrow the interruption (which may have happened during
633+
# the websocket handling or during the file watching)
634+
throw(InterruptException())
655635
end
656-
catch err
657-
if !isa(err, InterruptException)
658-
if VERBOSE[]
659-
@error "serve error" exception=(err, catch_backtrace())
660-
end
661-
throw(err)
636+
637+
# run the auxiliary function if there is one (by default this does
638+
# nothing)
639+
coreloopfun(counter, fw)
640+
# update the cycle counter and sleep (yields to other threads)
641+
counter += 1
642+
sleep(0.1)
643+
end
644+
catch err
645+
if !isa(err, InterruptException)
646+
if VERBOSE[]
647+
@error "serve error" exception=(err, catch_backtrace())
662648
end
663-
finally
664-
# cleanup: close everything that might still be alive
665-
print("\n⋮ shutting down LiveServer… ")
666-
# stop the filewatcher
667-
stop(fw)
668-
# close any remaining websockets
669-
for wss values(WS_VIEWERS)
670-
@sync for wsi in wss
671-
isopen(wsi.io) && @async begin
672-
try
673-
wsi.writeclosed = wsi.readclosed = true
674-
close(wsi.io)
675-
catch
676-
end
649+
throw(err)
650+
end
651+
finally
652+
# cleanup: close everything that might still be alive
653+
print("\n⋮ shutting down LiveServer… ")
654+
# stop the filewatcher
655+
stop(fw)
656+
# close any remaining websockets
657+
for wss values(WS_VIEWERS)
658+
@sync for wsi in wss
659+
isopen(wsi.io) && @async begin
660+
try
661+
wsi.writeclosed = wsi.readclosed = true
662+
close(wsi.io)
663+
catch
677664
end
678665
end
679666
end
680-
# empty the dictionary of viewers
681-
empty!(WS_VIEWERS)
682-
# shut down the server
683-
HTTP.Servers.forceclose(server)
684-
# reset other environment variables
685-
reset_content_dir()
686-
reset_ws_interrupt()
687-
println("")
688667
end
668+
# empty the dictionary of viewers
669+
empty!(WS_VIEWERS)
670+
# shut down the server
671+
HTTP.Servers.forceclose(server)
672+
# reset other environment variables
673+
reset_content_dir()
674+
reset_ws_interrupt()
675+
println("")
689676
end
690677
return nothing
691678
end

0 commit comments

Comments
 (0)