Upon downloading the project, follow these steps to set up your environment.
For each environment (Development, Staging, Production), you need to create a corresponding appsettings file.
- Copy
appsettings.ExampleEnvironment.jsonand rename it to match the environment:- For development:
appsettings.Development.json - For production:
appsettings.Production.json - For any other environment, use:
appsettings.{EnvironmentName}.json
- For development:
- Replace the placeholder values in the new files with actual values specific to your environment:
- DefaultConnection: Set your actual database connection string.
- In Development, the connection string uses the
{ServerName}placeholder. This will automatically be replaced with your machine's name at runtime.
- In Development, the connection string uses the
- FMPKey: Add your Financial Modeling Prep (FMP) API key.
- JWT: Update the
Issuer,Audience, andSigningKeywith valid values for JWT authentication. The signing key must match what your tokens will use.
- DefaultConnection: Set your actual database connection string.
{
"ConnectionStrings": {
"DefaultConnection": "Server={ServerName};Database=YourDatabaseName;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"FMPKey": "YourFMPKey",
"JWT": {
"Issuer": "http://localhost:5246",
"Audience": "http://localhost:5246",
"SigningKey": "YourSigningKey"
}
}If needed, adjust the CORS policy in Program.cs to allow specific origins instead of allowing all origins. By default, CORS is configured as follows:
app.UseCors(x => x
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.SetIsOriginAllowed(origin => true) // Allow any origin
);You can modify .SetIsOriginAllowed to only allow specific domains in production.
To run the API in development mode, use:
dotnet watch runThis will launch the API on http://localhost:5113 (HTTP) or https://localhost:7141 (HTTPS), as configured in the launchSettings.json file.
To publish the application, use the following command:
dotnet publish -c Release -o ./publishThis will create a release build and output the files to the ./publish directory.
Make sure to configure your environment settings and set appropriate environment variables in production.
If you prefer not to store sensitive values like the JWT signing key or database connection string in the appsettings files, you can set these values via environment variables:
- Database Connection: ConnectionStrings__DefaultConnection
- JWT Signing Key: JWT__SigningKey
- JWT Issuer: JWT__Issuer
- JWT Audience: JWT__Audience