Path / base-url issues in deploying Angular app

I’m deploying my first Angular app and I think I have problems of path or base url.

According to the server manager, the Web App is unique and serves multiple domains. Each domain is a unique USER with its own database and customizations. The App folder is located within the site that handles multi-domain requests.

Website folder on test/production servers: /www/website/
App folder on test/production servers: /www/website/pwa/

Example of the development, test and production urls:

Development: http://localhost:4200/

Local server test example:
https://test.myofficeserver.com/website_user1/pwa/
(url is solved by locating user1, as if the url https://test.myofficeserver.com/website/?user=user1 is visited)

Production server example:
https://www.user1domain.com/pwa/

So in my deployment, the app does not have the user url reference inside it, which then needs to be interpreted at the time it is requested.
I tried configuring two providers in app.config.ts to connect to a general end-point that would return the base url to me based on where the request came from :

{
  provide: APP_INITIALIZER,
  useFactory: getConfig,
  multi: true,
  deps: [CONFIG],
},
{
  provide: APP_BASE_HREF,
  useFactory: (config: Config) => config.baseHref,
  deps: [CONFIG],
}

So, in local server test in config.baseHref I receive: https://test.myofficeserver.com/website_user1

App root is loaded but not router-outlet, get error Error: NG04002: Cannot match any routes. URL Segment: ‘website_user1/pwa’ with url redirected to https://test.myofficeserver.com/

Looking on web I tried different solution, to hack base tag of index.html.
So I have removed providers and added into index.html:

<script>
  document.write(`<base href="${location.pathname}${location.pathname.endsWith('/') ? '' : '/'}"/>`);
</script>

Wow it works! But there are problems 🙁 . If I try to digit directly url with first route, it doesn’t work and I get server side 404:

https://test.myofficeserver.com/website_user1/pwa/ works and redirect me correctly to first route /dashboard, but if I try to visit directly https://test.myofficeserver.com/website_user1/pwa/dashboard I get server side 404 error.

When I develop without index.html’s hack on localhost, if I directly browse the url https://localhost:4200/dashboard it correctly resolves the route.

app.routes.ts

export const routes: Routes = [
  { path: 'login', component: LoginComponent},
  { path: 'dashboard', loadComponent: () => import('./features/dashboard/dashboard.component'), canActivate: [authGuard], canMatch: [isAdmin]},
  { path: 'addressbook', loadComponent: () => import('./features/addressbook/addressbook.component').then(c => c.AddressBookComponent), canActivate: [authGuard], canMatch: [isAdmin]},
  { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
];

In conclusion what is the correct way to handle this case of multi-domanis served by unique app? I couldn’t find any clear information, it seems like a borderline case but it seems strange to me.

I apologize for the length of the text, but it is difficult to make the situation clear and make the problem understood correctly.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Path / base-url issues in deploying Angular app

I’m deploying my first Angular app and I think I have problems of path or base url.

According to the server manager, the Web App is unique and serves multiple domains. Each domain is a unique USER with its own database and customizations. The App folder is located within the site that handles multi-domain requests.

Website folder on test/production servers: /www/website/
App folder on test/production servers: /www/website/pwa/

Example of the development, test and production urls:

Development: http://localhost:4200/

Local server test example:
https://test.myofficeserver.com/website_user1/pwa/
(url is solved by locating user1, as if the url https://test.myofficeserver.com/website/?user=user1 is visited)

Production server example:
https://www.user1domain.com/pwa/

So in my deployment, the app does not have the user url reference inside it, which then needs to be interpreted at the time it is requested.
I tried configuring two providers in app.config.ts to connect to a general end-point that would return the base url to me based on where the request came from :

{
  provide: APP_INITIALIZER,
  useFactory: getConfig,
  multi: true,
  deps: [CONFIG],
},
{
  provide: APP_BASE_HREF,
  useFactory: (config: Config) => config.baseHref,
  deps: [CONFIG],
}

So, in local server test in config.baseHref I receive: https://test.myofficeserver.com/website_user1

App root is loaded but not router-outlet, get error Error: NG04002: Cannot match any routes. URL Segment: ‘website_user1/pwa’ with url redirected to https://test.myofficeserver.com/

Looking on web I tried different solution, to hack base tag of index.html.
So I have removed providers and added into index.html:

<script>
  document.write(`<base href="${location.pathname}${location.pathname.endsWith('/') ? '' : '/'}"/>`);
</script>

Wow it works! But there are problems 🙁 . If I try to digit directly url with first route, it doesn’t work and I get server side 404:

https://test.myofficeserver.com/website_user1/pwa/ works and redirect me correctly to first route /dashboard, but if I try to visit directly https://test.myofficeserver.com/website_user1/pwa/dashboard I get server side 404 error.

When I develop without index.html’s hack on localhost, if I directly browse the url https://localhost:4200/dashboard it correctly resolves the route.

app.routes.ts

export const routes: Routes = [
  { path: 'login', component: LoginComponent},
  { path: 'dashboard', loadComponent: () => import('./features/dashboard/dashboard.component'), canActivate: [authGuard], canMatch: [isAdmin]},
  { path: 'addressbook', loadComponent: () => import('./features/addressbook/addressbook.component').then(c => c.AddressBookComponent), canActivate: [authGuard], canMatch: [isAdmin]},
  { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
];

In conclusion what is the correct way to handle this case of multi-domanis served by unique app? I couldn’t find any clear information, it seems like a borderline case but it seems strange to me.

I apologize for the length of the text, but it is difficult to make the situation clear and make the problem understood correctly.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật