Issue: Encountering a 404 Not Found error when trying to access fonts within the assets folder.
http://server.com/assets/fonts/Bold/RobotoCondensed-Bold.woff2
However, it works fine in local development:
http://localhost/assets/fonts/Bold/RobotoCondensed-Bold.woff2
Here are some details: The fonts are located inside the assets folder. They have been successfully copied to the docker image path:
/usr/share/nginx/html/assets/fonts/Bold/RobotoCondensed-Bold.woff2
When I request
http://server.com/service/assets/fonts/Bold/RobotoCondensed-Bold.woff2
,
the font is retrieved. The /service
prefix represents the name of the service being served.
The base href changes during local dev from <base href="/">
to
<base href="/service/">
on server.com
How can this issue be resolved? I could attempt changing the URL from
/assets/fonts/Light/RobotoCondensed-Light.woff2
to service/assets/fonts/Light/RobotoCondensed-Light.woff2
. However, this would cause the fonts to fail on the local environment where this prefix does not exist.
It's worth mentioning that the favicon.ico is correctly served.
In the local environment, the front end requests without a prefix while on the server it requests the favicon with the prefix /service. The favicon is only referenced in index.html
:
<link rel="icon" type="image/x-icon" href="favicon.ico" />
_fonts.scss file:
@font-face {
font-family: 'Roboto Condensed';
src: url('/assets/fonts/Light/RobotoCondensed-Light.woff2') format('woff2'),
url('/assets/fonts/Light/RobotoCondensed-Light.woff') format('woff');
font-weight: 300;
font-style: normal;
font-display: swap;
}
angular.json file:
"assets": [
"projects/service/src/favicon.ico",
"projects/service/src/assets"
],
"styles": [
"projects/service/src/assets/scss/modules/_fonts.scss"
],
I am new to Angular and frontend development and struggling to resolve this issue. Any assistance will be greatly appreciated.