What is best practise to deploy a docker image of my ember app in nginx where the rootURL might differ between environments? My scenario is as follows:
- Build an ember app with the environment set to production.
- Dockerize it in an nginx container.
- Ember data calls to a REST api sitting behind the nginx instance which proxy passes it through i.e.
/assets/etc
served from nginx (contains ember app/assets) and REST api on/api/v1/etc
that nginx proxy passes through. - The
serializers/application.js
has the namespace set toapi/v1
.
The above works great in my local dev docker engine, test and system test environments where the url is <domain>/index.html
and <domain>/api/v1/myrestendpoint
.
Unfortunately our production and UAT infrastructure is not the same in that we have a single subdomain say frontend.domain.com
which uses a load balancer to proxy requests to services behind based on a path immediately after the domain e.g. http://ift.tt/2fWHA3h
so to hit the nginx ember asset server the url would be http://ift.tt/2fEGWV0
. The routing works to that page but the pre-built ember app and assets that are returned have references to load additional assets from /assets
and not /customer1/assets
and so we get 404 and in the case of ember data REST calls 503.
My work around is to update the path using the sub_filter module in nginx e.g.
location / {
sub_filter_types *;
sub_filter 'assets' 'customer1/assets';
sub_filter '%22rootURL%22%3A%22/%22' '%22rootURL%22%3A%22/customer1/%22';
sub_filter 'rootURL:"/"' 'rootURL:"/customer1/"';
sub_filter_once off;
try_files $uri /index.html =404;
}
which fixes the path to css and js assets, updates the rootURL property in the ember ENV and does the same to the rootURL buried in the ember app js. This seems to work but it can't be the best way.
The other option might be to do something in the ember config/environment.js
and build for different deployment environments but this would violate our company policy of the same docker image going through test to production. This certainly won't help when we have a customer2 path as part of the url.
Can anyone suggest a solution?
Another issue I had was that Chrome refused to load my JS assets after changing the path in index.html with the integrity attribute generated by the build so I had to set integrity=""
which is not great either.
Aucun commentaire:
Enregistrer un commentaire