Repository navigation
Init of the Server and the files #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e4b2ac9
init(Server): Set up initial project structure with configuration fil…
FukuInTheCode 8d8457b
feat(controller): Add BaseController with custom Forbid method for ha…
FukuInTheCode 19a6638
feat(mongodb): Implement MongoDBContext for database connection and c…
FukuInTheCode b75ea63
chore: Add .gitkeep files to Mobile and Web directories for version c…
FukuInTheCode 53c9eff
chore: Add .gitkeep files to Server directories for version control
FukuInTheCode 1b994eb
docs: Add .gitkeep files to Server, Mobile, and Web directories for v…
FukuInTheCode 54bfe55
chore: Add .gitkeep files to Mobile, Server, and Web directories for …
FukuInTheCode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using MongoDB.Bson; | ||
| using MongoDB.Driver; | ||
|
|
||
| namespace Server.Contexts; | ||
|
|
||
| public static class MongoDBContext | ||
| { | ||
| public static MongoClient Client { get; set; } | ||
| private static object _lock = new object(); | ||
|
|
||
| static MongoDBContext() | ||
| { | ||
| if (Client != null) | ||
| return; | ||
|
|
||
| lock (_lock) | ||
| { | ||
| if (Client != null) | ||
| return; | ||
|
|
||
| Client = new MongoClient(Settings.MongoConnectionString); | ||
| Console.WriteLine("Settings.MongoConnectionString: " + Settings.MongoConnectionString); | ||
| } | ||
| } | ||
|
|
||
| public static IMongoDatabase GetDatabase(string databaseName) | ||
| { | ||
| return Client.GetDatabase(databaseName); | ||
| } | ||
|
|
||
| public static IMongoCollection<TModel> GetCollection<TModel>(string databaseName, string collectionName) | ||
| { | ||
| return GetDatabase(databaseName).GetCollection<TModel>(collectionName); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace Server.Controllers; | ||
|
|
||
| public class BaseController : ControllerBase | ||
| { | ||
| public BaseController() | ||
| { | ||
| } | ||
|
|
||
| protected ActionResult<T> Forbid<T>(T data) => StatusCode(StatusCodes.Status403Forbidden, data); | ||
| } |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,93 @@ | ||||||||||||
| using System.Text.Json; | ||||||||||||
| using Microsoft.AspNetCore.Authentication.JwtBearer; | ||||||||||||
| using Microsoft.IdentityModel.Tokens; | ||||||||||||
| using System.Text; | ||||||||||||
|
|
||||||||||||
| var builder = WebApplication.CreateBuilder(args); | ||||||||||||
|
|
||||||||||||
| // Add services to the container. | ||||||||||||
| builder.Services.AddControllers() | ||||||||||||
| .AddJsonOptions(options => | ||||||||||||
| { | ||||||||||||
| options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; | ||||||||||||
| options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| // Add HttpClient | ||||||||||||
| builder.Services.AddHttpClient(); | ||||||||||||
|
|
||||||||||||
| // Configure JWT Authentication | ||||||||||||
| builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) | ||||||||||||
| .AddJwtBearer(options => | ||||||||||||
| { | ||||||||||||
| var jwtKey = builder.Configuration["Jwt:Key"] ?? throw new Exception("JWT key not found"); | ||||||||||||
| var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? throw new Exception("JWT issuer not found"); | ||||||||||||
| var jwtAudience = builder.Configuration["Jwt:Audience"] ?? throw new Exception("JWT audience not found"); | ||||||||||||
|
|
||||||||||||
| options.TokenValidationParameters = new TokenValidationParameters | ||||||||||||
| { | ||||||||||||
| ValidateIssuerSigningKey = true, | ||||||||||||
| IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey)), | ||||||||||||
| ValidateIssuer = true, | ||||||||||||
| ValidateAudience = true, | ||||||||||||
| ValidIssuer = jwtIssuer, | ||||||||||||
| ValidAudience = jwtAudience, | ||||||||||||
| ClockSkew = TimeSpan.Zero | ||||||||||||
| }; | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| // Configure settings | ||||||||||||
| Settings.MongoConnectionString = builder.Configuration.GetConnectionString("MongoDB") ?? throw new Exception("MongoDB connection string not found"); | ||||||||||||
| Settings.JwtSettings = new JwtSettings | ||||||||||||
| { | ||||||||||||
| Key = builder.Configuration["Jwt:Key"] ?? throw new Exception("JWT key not found"), | ||||||||||||
| Issuer = builder.Configuration["Jwt:Issuer"] ?? throw new Exception("JWT issuer not found"), | ||||||||||||
| Audience = builder.Configuration["Jwt:Audience"] ?? throw new Exception("JWT audience not found"), | ||||||||||||
| ExpiryInDays = int.Parse(builder.Configuration["Jwt:ExpiryInDays"] ?? "7") | ||||||||||||
| }; | ||||||||||||
| // Add this line to listen on all interfaces | ||||||||||||
| builder.WebHost.ConfigureKestrel(options => | ||||||||||||
| { | ||||||||||||
| options.ListenAnyIP(5000); | ||||||||||||
| }); | ||||||||||||
|
Comment on lines
+48
to
+52
|
||||||||||||
| // Add this line to listen on all interfaces | |
| builder.WebHost.ConfigureKestrel(options => | |
| { | |
| options.ListenAnyIP(5000); | |
| }); |
FukuInTheCode marked this conversation as resolved.
Resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "http://localhost:5280", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "https://localhost:7015;http://localhost:5280", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <RuntimeIdentifier>linux-x64</RuntimeIdentifier> <!-- This line is the temp fix for the issue with the runtime identifier --> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" /> | ||
| <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.0.3" /> | ||
| <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" /> | ||
| <PackageReference Include="MongoDB.Driver" Version="3.0.0" /> | ||
| <PackageReference Include="MongoDB.Bson" Version="2.23.1" /> | ||
|
FukuInTheCode marked this conversation as resolved.
Resolved
|
||
| <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
| <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
| </Project> | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
Empty file.
Empty file.
Empty file.
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging the MongoDB connection string to console may expose sensitive credentials in logs. Consider removing this debug output or use proper logging with appropriate log levels that can be filtered in production.