Question presented to candidate: "The same Angular app is deployed at / in production, at /staging/ on a shared host, and at /tenant-name/ for some customers. How do you make it work everywhere, ideally without a separate build per tenant?"
What a strong answer should cover:
- The base href is the
<base href>tag inindex.html; the browser resolves every relative URL (scripts, styles, assets) against it, and the router uses it as the app's root path. - Build-time options:
ng build --base-href /staging/, or abaseHrefper configuration inangular.json(ng build -c production,staging). - Only
index.htmlchanges; the JavaScript bundles are byte-identical, so one build can be deployed under many paths by rewriting the tag at deploy time. - Runtime option for the router: provide
APP_BASE_HREF(it wins over the DOM tag), but it does not change how the browser loads relative asset URLs. - The value needs a trailing slash:
/shopresolvesmain.jsto/main.js. deployUrlis a different thing: it prefixes asset URLs (for a CDN) and leaves<base href>alone. The server must also fall back toindex.htmlfor deep links.
Clarifying questions expected:
- "Is the path known at build time, or only when the container starts or the request arrives?"
- "Are assets served from the same origin, or a CDN?"
Code / implementation expected: Yes β build configurations in angular.json, and an APP_BASE_HREF factory for a runtime path.