Quarkus, Heroku and different environments

醉酒当歌 提交于 2021-02-11 13:25:15

问题


I'm currently developing a simple webapp with seperated frontend (Vue) and backend (quarkus REST API) project. For now, I've setup a MVP, where the frontend is displaying some simple data which is called from the backend. To get a working MVP i need to setup CORS support. However, first i want to explain my setup:

Setup

I'm starting developing environment of my frontend with npm run serve and of my backend with ./mvnw quarkus:dev. Frontend is running on localhost:8081 and backend running on localhost:8080. Heroku allows to run your apps locally aswell with the command heroku local web. Frontend is running on port 0.0.0.0:5001 and backend on 0.0.0.0:5000.

To achieve this setup i setup two .env files on my frontend which are pointing to my backend api. If i want to work in development mode the file .env.development is loaded:

VUE_APP_ROOT_API=http://localhost:8080

and if i run heroku local web the file .env.local with

VUE_APP_ROOT_API=0.0.0.0:5000

is loaded.

In my backend I've set quarkus.http.cors=true in my application.properties.

Now I want to deploy those two projects to heroku and use it in production. Therefore I setup two heroku projects and set a config variable in my frontend project with the following value:

VUE_APP_ROOT_API:https://mybackend.herokuapp.com

Calls from my frontend are successfully working!

Question

For the next step, I want to restrict it more and just enable my frontend to call my API. I know i can set something like

quarkus.http.cors.origins=myfrontend.herokuapp.com

However, I dont know how i could do this on quarkus with different environments (development, local and production)? I've found this link but I don't know how to configure heroku and my backend app correctly. Do i need to setup different profiles which are applied on my different environments? Or is there another solution? Do i need Herokus Config Variables?

Thanks for the help so far!


回答1:


quarkus.http.cors.origins is overridable at runtime so you have several possibilities.

You could use a profile and have everything set up in your application.properties with %prod.quarkus.http.cors.origins=.... Then you either use -Dquarkus.profile=prod when launching your application or you use QUARKUS_PROFILE=prod as an environment variable.

Another option is to use an environment variable for quarkus.http.cors.origins. That would be QUARKUS_HTTP_CORS_ORIGINS=....

My recommendation would be to use a profile. That way you can safely check that all your configuration is consistent at a glance.



来源:https://stackoverflow.com/questions/59919359/quarkus-heroku-and-different-environments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!