Closed essenciary closed 3 years ago
is this fixable by adding an ingress layer (such as Nginx)? I have been trying to use the basic json example in a container but have not been able to access the Genie port from the host.
From the docker-compose.yml
:
...
julia:
container_name: julia_api
build:
context: .
command: julia --project="/opt/julia_src" api.jl
ports:
- "8081:8081"
and api.jl
:
using Genie, Genie.Router, Genie.Requests, Genie.Renderer.Json
include("REopt.jl")
using .REopt
Genie.config.run_as_server = true
route("/jsonpayload", method = POST) do
data = jsonpayload() # Dict{String,Any}
results = reopt(data)
json(results)
end
Genie.startup(8081)
I'm having the same problem. I don't know why but it will works when your host is 0.0.0.0
, but not 127.0.0.1
. Try
Genie.startup(8081, "0.0.0.0") # Genie use 127.0.0.1 by default
@ndgnuh I think that is the correct solution and it has to do with Docker networks (though it didn't work for me so I went with HTTP.jl instead - but it might not have worked for me because of unrelated problems).
Ah, I didn't read the docs thoroughly. You can change the environment using the GENIE_ENV
variable, the host and port will be configured by the config/env/$GENIE_ENV.jl
file. Change the host to 0.0.0.0
in the dev
environment (default) or use the prod
environment and everything will work.
Hi,
We deployed a Genie web API in a kubernetes cluster. After configuring the deployment, service and ingress, we could not reach the web API from outside. We had 404 or 502 errors.
The problem was that we were running Genie jl using the host 127.0.0.1
instead of 0.0.0.0
. So make sure you use 0.0.0.0
.
@guimarqu Thanks for the contribution. But it sounds like maybe you're not running the app in production mode (environment), as that, by default, will use 0.0.0.0
I strongly suggest you run it in production mode as that has a considerable and noticeable performance boost (it's optimized for performance, whereas the dev mode is optimized for building and debugging).
To do that you can either pass the environment variable GENIE_ENV=prod
or set ENV["GENIE_ENV"]="prod"
in config/global.jl
.
Thanks very much for your advices.
We tried to run it in prod but the host was 127.0.0.1 despite what's written in the prod configuration file. We are going to look more carefully for what we did wrong.
Thanks again !
You're welcome!
Weird... maybe you're passing the host explicitly? If you can reproduce, please open an issue. Thanks!
This still seems to happen. GENIE_ENV=prod
but serving from the wrong ip and port:
To reproduce you can use https://github.com/QuantumSavory/QuantikzServer.jl
as discussed in https://github.com/GenieFramework/Genie.jl/issues/651, my issue was that I was using Genie v5 to run an app created with Genie v1
@Krastanov ok, so you need to update the configuration file? Works well now?
yes, regenerating the app and copying over routes.jl fixed the issue
Per feedback in Gitter