How to load configuration dynamically in Next.js deployed app? - next.js

I want to have dynamic configuration for my Next.js project.
I want to be able to change it after Next.js is built and deployed.
Right now I'm using .env and .env.production which are part of dotenv repo. But it seems that Next.js or dotenv compile the content and there is no way to change them dynamically.
How can I do that?

You can't change .env after building and deploying. But a workaround is always there.
Put a JSON file separated from the project and host in the server. Read the JSON file from that server and use that variable in the configuration. But there is a security issue if you put secrets and credentials in that JSON. for that, you can write a simple node project with returning JSON configuration using API. Use a token key to access that API. Put this token secret in that node project. So, changing those variables in that node or JSON project will be more cost-effective than rebuilding and deploying again the whole project.
or simply put those configuration in database.

Related

Gitlab API access project by it's old path before moving?

Using the Gitlab API I can retrieve a single project by it's path.
Once I moved a project Gitab is so nice, to redirect users accessing the old URL to new projects and tell them to change their bookmarks:
Unfortunately trying to access the old path via the API simply fails.
Is there a way to extract the new project path if I only got the old path using the Gitlab API?
Background is that we have some tooling that extracts the projects path from the git remote host and performs some actions.
After moving some projects we would like to perform some update actions using the tooling.

Manage User Secrets in a custom config file

I have a Xamarin.Forms app. As it does not have built in configuration file, I used a solution found here:
https://www.andrewhoefling.com/Blog/Post/xamarin-app-configuration-control-your-app-settings
and here
https://github.com/HoeflingSoftware/XamarinAppSettings
So now I have a custom appsettings.json file. The secrets in the file are replaced in AzureDevops pipeline. But how can I run the app from Visual Studio (on an emulator)? If it was a web application, I would use Manage User Secrets functionality, which would store the secrets in my file system. So it would be used automatically when the app is running during development. But how can I do it for a Xamarin.Forms app with its custom json file?
You could use the Replace Text in Source Files task on Marketplace to replace text in your source, before you build the project. You can then store the secret as a secure value in the pipeline variables library.
We use a similar approach to update the build versions for Xamarin Apps and for providing access to the Signing files.

Security Config File Firebase

Is it safe to keep the firebase config file (with the APIkey)when deploying my mobile app (front-end react native) to the google play store and app store?
How can I make it safer?
As Doug commented, the google-services.json (or google-services.plist file for iOS) does not contain any secret credentials. It merely contains the configuration data that your app needs to find its Firebase project on the servers. So sharing it with other developers on your app is not only safe, it's required for them to build an app that communicates with the same Firebase project.
You may want to consider keeping it out of version control though, and instead only deploy it onto your build server. The reason for this is not as much that that data is secret, but more that each developer should typically set up their own Firebase project for their development work. That way they won't be stepping onto each other's toes during feature development work.
Also see:
Is it safe to expose Firebase apiKey to the public?
Should I add the google-services.json (from Firebase) to my repository?

How can I change a setting in appsettings.json after auto-deploy?

I have an ASP.NET Core application going on an have setup Github auto-deploy on it. But since it's an open repo I obviously don't want to upload my correct configuration file.
What I'd like to do is to replace some strings in the appsettings.json after a github auto deploy.
"AppSettings": {
"Token": "my super duper secret token"
}
How can I change my super duper secret token to my real token after a github deploy on Azure?
As I know we can config token in App Settings on the Azure port.
I do a test on this, it works successfully, the following is my detail steps.
Create an Asp.net core Application.
Add [AppSettings] section in the appsetting.json file (Token vaule: mysecretkey).
Add a public class AppSettings.cs under the created project.
Add the code services.Configure<AppSettings>(Configuration.GetSection("AppSettings")) in the function ConfigureService function in the Startup.cs file (For .net Core 1.0).
Note:The syntax for model binding has changed from RC1 to RC2. Using services.Configure<AppSettings>(Configuration.GetSection("AppSettings")), is no longer availableIn order to bind a settings class to your configuration you need to configure this in the ConfigureServices method of Startup.cs:
services.Configure<AppSettings>(options => Configuration.GetSection("AppSettings").Bind(options));
5. Add code to the HomeController.cs file.
Publish the WebApp to the Azure Portal.
Add [AppSettings: Token] in the Azure Portal.
Browse the WebApp and select the about tab to see the token value is that the value set in the portal.
Assuming the web site already exists as a resource in Azure, you can simply set the App Settings/Connection strings in the portal. These will override the ones in the appsettings.json file at runtime. Ie. your app will first look at the azure app settings/connection strings before looking for them in the local file. This is part of asp.net core's "cloud first" approach to configuration management. These settings wont get overwritten when you deploy code to the app/slot.
Found a blog post here which describes it in a bit more detail, using the .AddEnvironmentVariables() call to add azure slot settings to the configuration.
There is a code editing functionality in developer tools settings (Settings -> Development Tools -> App Service Editor (Preview)). You can go there and change any file you like in there. But you probably will need to restart the web application (by editing web.config or some other way).. You can also use Kudu (Advanced Tools) for that, but it's not as pleasant UI as Visual Studio Code in the first option.
Though the more advanced and correct way of dealing with application secrets is the special secret manager. You can read more about it on asp.net documentation here.
Generally it's a way to load the secrets from a protected data storage and override them with environmental variables in production (can be set in azure web app).
If you are using Azure DevOps Release to deploy, you can easily specify properties for each environment/stage.
You can use the task File Transform and indicate the path to appsettings.json:
Or if you are deploying directly to Azure:
So you just need to create the variables to override the data in the settings:

Elastic Beanstalk deployment of Spring Boot application - where to put the external application.properties

I am deploying a Spring Boot application to AWS Elastic Beanstalk using AWSCLI. I want to put an external application.properties file containing customer specification configurations (database credentials, etc.) in the same directory of the application. The application should pick up this properties file. How can I accomplish that? Are there any alternatives?
Spring Cloud Config
This project allows you to use an external, centralized configuration repository for one or more applications. You don't need to rebuild your application if a property changes. You can simply change the property in your configuration repository and even push the changes to all of your applications.
See this Getting Started Guide.
This above approach is what I would recommend for the scenario you described. I would not bother with having a separate directory on the application server for your configuration files. Spring Cloud Config is a great approach as it solves the problem you described and a few more.
You can alternatively specify them in an application-prod property like
server.port=5000
spring.datasource.url=jdbc:mysql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.username=${RDS_USERNAME}
spring.datasource.password=${RDS_PASSWORD}
spring.jpa.hibernate.ddl-auto=create
and specify an environment variable called SPRING_PROFILES_ACTIVE with the value prod making the beanstalk smart enough to pick values from out there.

Resources