Genie Discord forum
Hi everyone! I'm trying to automatically force compile certain routes when launching a server using bin\repl or bin\server. I've seen the script below but I'm not sure where to put something like this in the directory to have it run correctly. As I understand it, force_compile() would need to run immediately before up(). Any suggestions?
using Genie, Genie.Router, Genie.Requests, Genie.Renderer.Json route("/foo") do json(:foo => "Foo") end route("/bar") do json(:bar => "Bar") end function force_compile() sleep(5) for (name, r) in Router.named_routes() Genie.Requests.HTTP.request(r.method, "http://localhost:8000" * tolink(name)) end end @async force_compile() up(async = false)
I haven't personally used
force_compile what do you think it does and what are you trying achieve? I'll have a look
that should work
I put it at the end of my routes.jl file with a 10 second delay. It seems to be working as expected as long as I run
up() quickly after
if the server is not running then it won't respond to the requests you're making
force_compile running async won't crash the app but it won't have any effect on the compilation either
That works for me. Thanks so much!