0

I would like to know if you can configure the base href as an environment variable of a tomcat or application server.

for example:

index.html

<base href="/${environment.tomcat}/">

or an environment variable for the operating system?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Dani
  • 11
  • 2
  • 4

1 Answers1

2

environment.ts

export const environment = {
  production: false,
  tomcat: '/'
};

environment.prod.ts

export const environment = {
  production: true,
  tomcat: '/my-app/'
};

And in your app module:~

import { Component, NgModule } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { environment } from '../environments/environment';

@NgModule({
  providers: [{provide: APP_BASE_HREF, useValue: environment.tomcat}]
})
class AppModule {}

OR

Using Angular CLI built-in feature:~

# Sets base tag href to /myUrl/ in your index.html
ng build --base-href /myUrl/
ng build -bh /myUrl/

you can update scripts in package.json:~

"scripts": {
  //...
  "start": "ng serve -bh /anotherUrl/",
  "build": "ng build -bh /tomcatServerURL/",
  //..
},

Hope this is helpful!

Sourav Dutta
  • 1,267
  • 1
  • 19
  • 25