Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
neozhu committed Sep 23, 2024
1 parent 9250f10 commit 8d0f72a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ COPY ["PdfGeneratorApi.csproj", "./"]
# RUN playwright install --with-deps chromium

# Set an environment variable (optional)
ENV API_KEY=your-api-key-here
# ENV API_KEY=your-api-key-here

ENTRYPOINT ["dotnet", "PdfGeneratorApi.dll"]
7 changes: 4 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@
await context.Response.WriteAsync("API Key is missing");
return;
}

// Get the API Key from environment variables
var apiKey = Environment.GetEnvironmentVariable("API_KEY");
// Get the configuration service
var config = context.RequestServices.GetRequiredService<IConfiguration>();
// Get the API Key from appsettings.json
var apiKey = config.GetValue<string>("ApiKey");
if (string.IsNullOrEmpty(apiKey) || !apiKey.Equals(extractedApiKey))
{
context.Response.StatusCode = 401; // Unauthorized
Expand Down
3 changes: 1 addition & 2 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"launchBrowser": true,
"applicationUrl": "https://localhost:7030;http://localhost:5215",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"API_KEY": "your-api-key-here"
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ApiKey": "your-api-key-here"
}

0 comments on commit 8d0f72a

Please sign in to comment.