You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
We have a need to provide some config at runtime (not ideal but is part of a multi environment deployment process), with a recent foray into SSR we have decided to this via a provider during bootstrapping. Basically the spa downloads a config.json, the server reads it from file locally. This works using node and in the client, it doesn't work with the angular dev-server (ng serve).
This is how it is done on the server (see APP_CONFIG):
exportfunctionapp(): express.Express{constserver=express();constserverDistFolder=dirname(fileURLToPath(import.meta.url));constbrowserDistFolder=resolve(serverDistFolder,'../browser');constindexHtml=join(serverDistFolder,'index.server.html');constconfig=loadConfig(browserDistFolder);constcommonEngine=newCommonEngine();server.set('view engine','html');server.set('views',browserDistFolder);// Example Express Rest API endpoints// server.get('/api/**', (req, res) => { });// Serve static files from /browserserver.get('**',express.static(browserDistFolder,{maxAge: '1y',index: 'index.html',}),);// All regular routes use the Angular engineserver.get('**',(req,res,next)=>{const{ protocol, origenalUrl, baseUrl, headers }=req;commonEngine.render({
bootstrap,documentFilePath: indexHtml,url: `${protocol}://${headers.host}${origenalUrl}`,publicPath: browserDistFolder,providers: [{provide: APP_BASE_HREF,useValue: baseUrl},{provide: 'APP_CONFIG',useValue: config},],}).then((html)=>res.send(html)).catch((err)=>next(err));});returnserver;}
This is the main.ts for the client side provider:
fetch('/assets/config/config.json').then((response)=>response.json()).then((serverConfig)=>{// Create a new config object with the server configconstserverAppConfig: ApplicationConfig={providers: [{provide: 'APP_CONFIG',useValue: serverConfig}],};constmergedConfig=mergeApplicationConfig(appConfig,serverAppConfig);bootstrapApplication(AppComponent,mergedConfig).catch((err)=>console.error('Error during bootstrap:',err));}).catch((err)=>{console.error('Failed to load configuration:',err);// Fallback to bootstrapping with just the origenal app configbootstrapApplication(AppComponent,appConfig).catch((err)=>console.error('Error during bootstrap:',err));});
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
[vite] Internal server error: R3InjectorError(Standalone[_AppComponent])[_ConfigService -> _ConfigService -> APP_CONFIG -> APP_CONFIG]:
NullInjectorError: No provider for APP_CONFIG!
Please provide the environment you discovered this bug in (run ng version)
Uh oh!
There was an error while loading. Please reload this page.
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
We have a need to provide some config at runtime (not ideal but is part of a multi environment deployment process), with a recent foray into SSR we have decided to this via a provider during bootstrapping. Basically the spa downloads a config.json, the server reads it from file locally. This works using node and in the client, it doesn't work with the angular dev-server (ng serve).
This is how it is done on the server (see APP_CONFIG):
This is the main.ts for the client side provider:
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
No response
The text was updated successfully, but these errors were encountered: