I have a project created using the VS 2022 ASP.NET Core with Angular template.
Everything about the project itself is good, but I am trying to figure out how to get the Angular app to load the .NET Core's appsettings.json
to use for config, so it's one shared file for ease of use/deployment.
The file structure of the deployed project looks like
- Main Deployment Folder
api.exe
(and all other framework files)appsettings.json
wwwroot
folderassets
folderindex.html
(and all other Angular files)
Initially I went down the path of creating an Angular service to load config from a file as in this answer https://stackoverflow.com/a/54793384/12899737
However, I then realized that I couldn't point to the appsettings.json
in the deployment folder above the wwwroot
as that is not being served in the same way and so it was unavailable.
I could use the angular.json
build settings to include the appsettings, but that just creates a copy of it at build time and puts you back to essentially having to manage 2 config files.
I am also aware that some examples serve the config settings via an API call, I'm considering that as a last resort option but would prefer to keep it file based if possible.
The main 2 questions I have are:
Is there any way to have a service in the Angular app served from the
wwwroot
folder that can access theappsettings.json
file directly in the parent folder, without that file being served?Is it crazy to consider moving the
appsettings.json
down a folder into thewwwroot
so the Angular app has access to it, and then editing theWebApplication.CreateBuilder(args)
in the API to include that location forappsettings.json
?
Thank you for your input!