Skip to content

Add support for deployUrl #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SchnWalter opened this issue Jun 12, 2020 · 5 comments
Closed

Add support for deployUrl #143

SchnWalter opened this issue Jun 12, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@SchnWalter
Copy link
Contributor

SchnWalter commented Jun 12, 2020

Why

Currently, the application works properly only on the domain or subdomain root. If it's moved to a subpath, various resources that contain URLs that start with slash (assets paths, window.href "forced-reloads") won't work

What

@SchnWalter SchnWalter added the enhancement New feature or request label Jun 12, 2020
@koekj
Copy link

koekj commented Jul 16, 2021

If possible it would also be nice if the deploymentUrl can be made available in the application itself. As for instance I'm using configuration that relates to the deployment url as startng path. Another option would be to use a macro ${angular.deployUrl} in the generation of the code so that it can be replace in run time?

@SchnWalter
Copy link
Contributor Author

SchnWalter commented Jul 16, 2021

I haven't checked, and it isn't immediately obvious from the standard, but since <a href="#anchor">Anker</a> produces an URL that contains the base, you should be able to use the URL class to retrieve the deployUrl, so a simple wrapper service will probably do the trick.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

Thanks for mentioning this.

L.E. I just realized that the above won't work unless you take an element from the DOM, see:

https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI

@koekj
Copy link

koekj commented Jul 16, 2021

I;m using two parameters the deploy url and the base-href which I then manipulate in the index.html
I'm using currently @{angular.deployUrl} as deployUrl and then run a script on runtime over .js,.html,.css and .json to replace this macro in the real url
find dist/$APP_NAME \\( -type d -name .git -prune \\) -o -type f \\( -iname '*.css' -o -iname '*.html' -o -iname '*.js' -o -iname '*.json' \\) -print0 | xargs -0 sed -i \"s|@{angular\\.deployUrl}|$APP_DEPLOY_URL|g\" && node dist/$APP_NAME/server/$APP_LANG/main.js --appName=$APP_NAME --baseUrl=$APP_BASE_URL --configFile=$APP_CONFIG_FILE --deployUrl=$APP_DEPLOY_URL --lang=$APP_LANG"
The @{} is used not to interfer with the enviroment ${} (taken principle from spring boot)

As the -- variables are passed on to the server.ts I can use them with providers within my app to retrieve, this enables me to use hardcoded language specific configuration files that are relative to the deploy-url. The deploy-url is passed in the SSR engine with a provider so that I can retrieve it on the server. I'm using transfer states to get the url if the client is booted in the browser.
I can check if I'm on the server by using the isPlatformServer and then try to load the deploy-url with the injector manually.

By using the APP_NAME I can have one script that starts multiple different apps as every app is outputted to dist/<app_name>.

So I hope I made clear why I need the deploy-url and it should be run time available so that I can move my app's under multiple url's without rebuilding.

The only problem which I now have is that I need to start multiple server modules. I'm still trying to find a solution to load a language build within the same server so that I don't need a deployment per language but can use one nodejs server which hosts multiple languages/multiple apps.

@SchnWalter
Copy link
Contributor Author

I would go with some different translation system that allows you to change the language at runtime, @ngx-translate/core is a good one, but you should probably replace the default pipe, since it does a lot of work during Change Detection. And I think that SSR should work out of the box, just make sure to add the language codes in the URL.

@SchnWalter
Copy link
Contributor Author

Closing, deployUrl is now deprecated: angular/angular-cli@e95ecb8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants