From 92e47c04a8f98663eef40190b8b09898f09951db Mon Sep 17 00:00:00 2001 From: Raaed Bucksimiar <85855492+Deathbot545@users.noreply.github.com> Date: Sun, 1 Feb 2026 08:31:10 +0530 Subject: [PATCH] Configure docker env and cors for local/prod --- .env | 18 +++++++ .env.example | 20 +++++++ ..._Ordering_API_appsettings.Development.json | 9 ++++ .../Food_Ordering_API_appsettings.json | 17 +++--- Food_Ordering_API/Program.cs | 44 +++++++-------- Food_Ordering_Web/appsettings.json | 24 ++++----- .../Kitchen_Web_appsettings.Development.json | 9 ++++ Kitchen_Web/Kitchen_Web_appsettings.json | 23 ++++---- Kitchen_Web/Program.cs | 40 +++++++------- .../Menu_API_appsettings.Development.json | 9 ++++ Menu_API/Menu_API_appsettings.json | 9 +++- Menu_API/Program.cs | 51 ++++++++---------- .../Order_API_appsettings.Development.json | 9 ++++ Order_API/Order_API_appsettings.json | 10 ++-- Order_API/Program.cs | 47 ++++++++-------- Restaurant_API/Program.cs | 54 ++++++++----------- ...estaurant_API_appsettings.Development.json | 9 ++++ .../Restaurant_API_appsettings.json | 19 ++++--- docker-compose.yml | 40 +++++++------- 19 files changed, 280 insertions(+), 181 deletions(-) create mode 100644 .env create mode 100644 .env.example diff --git a/.env b/.env new file mode 100644 index 00000000..19f5f91e --- /dev/null +++ b/.env @@ -0,0 +1,18 @@ +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres + +APPLICATION_DB_CONNECTION=Host=postgres;Port=5432;Database=ApplicationDb;Username=postgres;Password=postgres +OUTLET_DB_CONNECTION=Host=postgres;Port=5432;Database=OutletDb;Username=postgres;Password=postgres +MENU_DB_CONNECTION=Host=postgres;Port=5432;Database=MenuDb;Username=postgres;Password=postgres + +MONGO_CONNECTION_STRING=mongodb://mongo:27017 +MONGO_DATABASE=FoodOrdering + +JWT_KEY=dev-super-secret-key +JWT_ISSUER=dev +JWT_AUDIENCE=dev + +FOOD_ORDERING_API_BASE_URL=http://food-ordering-api/ +RESTAURANT_API_BASE_URL=http://restaurant-api/ + +ALLOWED_ORIGINS=http://localhost:8088,http://localhost:8089 diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..d59d1d13 --- /dev/null +++ b/.env.example @@ -0,0 +1,20 @@ +# Local defaults - copy to .env and tweak for production/AWS +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres + +APPLICATION_DB_CONNECTION=Host=postgres;Port=5432;Database=ApplicationDb;Username=postgres;Password=postgres +OUTLET_DB_CONNECTION=Host=postgres;Port=5432;Database=OutletDb;Username=postgres;Password=postgres +MENU_DB_CONNECTION=Host=postgres;Port=5432;Database=MenuDb;Username=postgres;Password=postgres + +MONGO_CONNECTION_STRING=mongodb://mongo:27017 +MONGO_DATABASE=FoodOrdering + +JWT_KEY=dev-super-secret-key +JWT_ISSUER=dev +JWT_AUDIENCE=dev + +FOOD_ORDERING_API_BASE_URL=http://food-ordering-api/ +RESTAURANT_API_BASE_URL=http://restaurant-api/ + +# Comma-separated list of allowed origins for APIs and Kitchen_Web +ALLOWED_ORIGINS=http://localhost:8088,http://localhost:8089 diff --git a/Food_Ordering_API/Food_Ordering_API_appsettings.Development.json b/Food_Ordering_API/Food_Ordering_API_appsettings.Development.json index cf46bff9..aacb64d9 100644 --- a/Food_Ordering_API/Food_Ordering_API_appsettings.Development.json +++ b/Food_Ordering_API/Food_Ordering_API_appsettings.Development.json @@ -2,6 +2,15 @@ "ConnectionStrings": { "ApplicationDbConnection": "Host=localhost;Port=5432;Database=ApplicationDb;User ID=postgres;Password=postgres;" }, + "Cors": { + "AllowedOrigins": [ + "http://localhost:5002", + "http://localhost:5003", + "http://localhost:5173", + "http://localhost:8088", + "http://localhost:8089" + ] + }, "Jwt": { "Key": "dev-super-secret-key-change-me", "Issuer": "dev", diff --git a/Food_Ordering_API/Food_Ordering_API_appsettings.json b/Food_Ordering_API/Food_Ordering_API_appsettings.json index bd011a7a..a8d20e4b 100644 --- a/Food_Ordering_API/Food_Ordering_API_appsettings.json +++ b/Food_Ordering_API/Food_Ordering_API_appsettings.json @@ -15,18 +15,23 @@ } }, "ConnectionStrings": { - "ApplicationDbConnection": "Host=restroapi.cz0qqo02m0na.eu-west-1.rds.amazonaws.com;Port=5432;Database=ApplicationDb;User ID=postgres;Password=NxPostgrsql;" + "ApplicationDbConnection": "Host=your-db-host;Port=5432;Database=ApplicationDb;Username=postgres;Password=change-me;" + }, + "Cors": { + "AllowedOrigins": [ + "https://your-domain.example" + ] }, "Authentication": { "Google": { - "ClientId": "247244252156-cqtuh8m6k4s6mcumhkri2grnkf5g5a8d.apps.googleusercontent.com", - "ClientSecret": "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" + "ClientId": "change-me", + "ClientSecret": "change-me" } }, "Jwt": { - "Key": "YourSecretKeyHere", - "Issuer": "YourIssuer", - "Audience": "YourAudience" + "Key": "change-me", + "Issuer": "change-me", + "Audience": "change-me" }, "AllowedHosts": "*" } diff --git a/Food_Ordering_API/Program.cs b/Food_Ordering_API/Program.cs index 901a52d3..22bd8192 100644 --- a/Food_Ordering_API/Program.cs +++ b/Food_Ordering_API/Program.cs @@ -79,29 +79,13 @@ // CORS builder.Services.AddCors(options => { + var allowedOrigins = GetAllowedOrigins(builder.Configuration); options.AddPolicy("AllowMyOrigins", policy => { - if (env.IsDevelopment()) - { - policy.WithOrigins( - "http://localhost:5002", - "http://localhost:5003", - "http://localhost:5173" - ) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - } - else - { - policy.WithOrigins( - "https://restosolutionssaas.com:8443", - "https://restosolutionssaas.com" - ) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - } + policy.WithOrigins(allowedOrigins) + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); }); }); @@ -109,7 +93,6 @@ // Logging + migrations var logger = app.Services.GetRequiredService>(); -var cs = builder.Configuration.GetConnectionString("ApplicationDbConnection"); logger.LogInformation("ApplicationDbConnection configured."); using (var scope = app.Services.CreateScope()) @@ -148,3 +131,20 @@ app.MapControllers(); app.Run(); + +static string[] GetAllowedOrigins(IConfiguration configuration) +{ + var origins = configuration.GetSection("Cors:AllowedOrigins").Get(); + if (origins is { Length: > 0 }) + { + return origins; + } + + var rawOrigins = configuration["Cors:AllowedOrigins"]; + if (!string.IsNullOrWhiteSpace(rawOrigins)) + { + return rawOrigins.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + } + + throw new InvalidOperationException("Cors:AllowedOrigins is missing. Configure it in appsettings or env vars."); +} diff --git a/Food_Ordering_Web/appsettings.json b/Food_Ordering_Web/appsettings.json index 27ecf516..3133bba9 100644 --- a/Food_Ordering_Web/appsettings.json +++ b/Food_Ordering_Web/appsettings.json @@ -1,28 +1,28 @@ { "ConnectionStrings": { - "DefaultConnection": "Host=database-1.cmnkfdahsas3.eu-north-1.rds.amazonaws.com;Port=5432;Database=Food_Ordering;User Id=postgres;Password=NxPostgrsql;" + "DefaultConnection": "Host=your-db-host;Port=5432;Database=Food_Ordering;Username=postgres;Password=change-me;" }, "Jwt": { - "Key": "YourSecretKeyHere", - "Issuer": "YourIssuer", - "Audience": "YourAudience" + "Key": "change-me", + "Issuer": "change-me", + "Audience": "change-me" }, "StripeSettings": { - "ApiKey": "sk_test_51NjhBQFU6tKdw4REQ4sdK5t4EUN3aNkvW7Z3v9e41eXjEgfHwcnFztdPvwrRIFeGgwuMpzvkrcn8CSghhoCbJS9S006L3W13JP", - "WebhookSecret": "pk_test_51NjhBQFU6tKdw4RE8kO4funmhbcbtQur1zsSD3YNbNBBAYQRZqR1omJtSp4KesSL3eHKPr03uZnuCoWUK233DYvD00wd9n7wfQ" + "ApiKey": "change-me", + "WebhookSecret": "change-me" }, "EmailSettings": { "Host": "smtp.gmail.com", "Port": 587, - "Email": "sitewebsite73@gmail.com", - "Password": "otrzdbifusqsiuoc" + "Email": "change-me@example.com", + "Password": "change-me" }, "Authentication": { "Google": { - "ClientId": "247244252156-cqtuh8m6k4s6mcumhkri2grnkf5g5a8d.apps.googleusercontent.com", - "ClientSecret": "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" + "ClientId": "change-me", + "ClientSecret": "change-me" } }, "Logging": { @@ -33,7 +33,7 @@ } }, "ShowDetailedErrors": true, - "ApiBaseUrl": "https://restosolutionssaas.com/", - "RestaurantApiBaseUrl": "https://restosolutionssaas.com/", + "ApiBaseUrl": "https://your-domain.example/", + "RestaurantApiBaseUrl": "https://your-domain.example/", "AllowedHosts": "*" } diff --git a/Kitchen_Web/Kitchen_Web_appsettings.Development.json b/Kitchen_Web/Kitchen_Web_appsettings.Development.json index 35e6e4f6..e8bbca87 100644 --- a/Kitchen_Web/Kitchen_Web_appsettings.Development.json +++ b/Kitchen_Web/Kitchen_Web_appsettings.Development.json @@ -1,5 +1,14 @@ { "ApiBaseUrl": "http://localhost:5000/", + "Cors": { + "AllowedOrigins": [ + "http://localhost:5002", + "http://localhost:5003", + "http://localhost:5173", + "http://localhost:8088", + "http://localhost:8089" + ] + }, "Jwt": { "Key": "dev-super-secret-key", "Issuer": "dev", diff --git a/Kitchen_Web/Kitchen_Web_appsettings.json b/Kitchen_Web/Kitchen_Web_appsettings.json index 7f8d5bea..08294993 100644 --- a/Kitchen_Web/Kitchen_Web_appsettings.json +++ b/Kitchen_Web/Kitchen_Web_appsettings.json @@ -1,21 +1,26 @@ { "ConnectionStrings": { - "DefaultConnection": "Host=database-1.cmnkfdahsas3.eu-north-1.rds.amazonaws.com;Port=5432;Database=Food_Ordering;User Id=postgres;Password=NxPostgrsql;" + "DefaultConnection": "Host=your-db-host;Port=5432;Database=Food_Ordering;Username=postgres;Password=change-me;" + }, + "Cors": { + "AllowedOrigins": [ + "https://your-domain.example" + ] }, "StripeSettings": { - "ApiKey": "sk_test_51NjhBQFU6tKdw4REQ4sdK5t4EUN3aNkvW7Z3v9e41eXjEgfHwcnFztdPvwrRIFeGgwuMpzvkrcn8CSghhoCbJS9S006L3W13JP", - "WebhookSecret": "pk_test_51NjhBQFU6tKdw4RE8kO4funmhbcbtQur1zsSD3YNbNBBAYQRZqR1omJtSp4KesSL3eHKPr03uZnuCoWUK233DYvD00wd9n7wfQ" + "ApiKey": "change-me", + "WebhookSecret": "change-me" }, "EmailSettings": { "Host": "smtp.gmail.com", "Port": 587, - "Email": "sitewebsite73@gmail.com", - "Password": "otrzdbifusqsiuoc" + "Email": "change-me@example.com", + "Password": "change-me" }, "Authentication": { "Google": { - "ClientId": "247244252156-cqtuh8m6k4s6mcumhkri2grnkf5g5a8d.apps.googleusercontent.com", - "ClientSecret": "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" + "ClientId": "change-me", + "ClientSecret": "change-me" } }, "Logging": { @@ -26,7 +31,7 @@ } }, "ShowDetailedErrors": true, - "ApiBaseUrl": "https://restosolutionssaas.com/", - "RestaurantApiBaseUrl": "https://restosolutionssaas.com/", + "ApiBaseUrl": "https://your-domain.example/", + "RestaurantApiBaseUrl": "https://your-domain.example/", "AllowedHosts": "*" } diff --git a/Kitchen_Web/Program.cs b/Kitchen_Web/Program.cs index c7cab0c5..c94ab434 100644 --- a/Kitchen_Web/Program.cs +++ b/Kitchen_Web/Program.cs @@ -97,26 +97,13 @@ // CORS (env-aware) builder.Services.AddCors(options => { + var allowedOrigins = GetAllowedOrigins(builder.Configuration); options.AddPolicy("AllowMyOrigins", policy => { - if (env.IsDevelopment()) - { - policy.WithOrigins( - "http://localhost:5002", - "http://localhost:5003", - "http://localhost:5173" - ) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - } - else - { - policy.WithOrigins("https://restosolutionssaas.com") - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - } + policy.WithOrigins(allowedOrigins) + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); }); }); @@ -156,3 +143,20 @@ app.MapControllers(); app.Run(); + +static string[] GetAllowedOrigins(IConfiguration configuration) +{ + var origins = configuration.GetSection("Cors:AllowedOrigins").Get(); + if (origins is { Length: > 0 }) + { + return origins; + } + + var rawOrigins = configuration["Cors:AllowedOrigins"]; + if (!string.IsNullOrWhiteSpace(rawOrigins)) + { + return rawOrigins.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + } + + throw new InvalidOperationException("Cors:AllowedOrigins is missing. Configure it in appsettings or env vars."); +} diff --git a/Menu_API/Menu_API_appsettings.Development.json b/Menu_API/Menu_API_appsettings.Development.json index b53246b7..14f55274 100644 --- a/Menu_API/Menu_API_appsettings.Development.json +++ b/Menu_API/Menu_API_appsettings.Development.json @@ -2,6 +2,15 @@ "ConnectionStrings": { "MenuDbConnection": "Host=localhost;Port=5432;Database=MenuDb;User Id=postgres;Password=postgres;" }, + "Cors": { + "AllowedOrigins": [ + "http://localhost:5002", + "http://localhost:5003", + "http://localhost:5173", + "http://localhost:8088", + "http://localhost:8089" + ] + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/Menu_API/Menu_API_appsettings.json b/Menu_API/Menu_API_appsettings.json index a24b1be1..d6d7d9f3 100644 --- a/Menu_API/Menu_API_appsettings.json +++ b/Menu_API/Menu_API_appsettings.json @@ -6,7 +6,12 @@ } }, "ConnectionStrings": { - "MenuDbConnection": "Host=menuapi.cz0qqo02m0na.eu-west-1.rds.amazonaws.com;Port=5432;Database=MenuDb;User Id=postgres;Password=NxPostgrsql;" + "MenuDbConnection": "Host=your-db-host;Port=5432;Database=MenuDb;Username=postgres;Password=change-me;" + }, + "Cors": { + "AllowedOrigins": [ + "https://your-domain.example" + ] }, "AllowedHosts": "*" -} \ No newline at end of file +} diff --git a/Menu_API/Program.cs b/Menu_API/Program.cs index 4ed57327..7309dbf3 100644 --- a/Menu_API/Program.cs +++ b/Menu_API/Program.cs @@ -41,26 +41,13 @@ // --------------------------- builder.Services.AddCors(options => { + var allowedOrigins = GetAllowedOrigins(builder.Configuration); options.AddPolicy("AllowMyOrigins", policy => { - if (env.IsDevelopment()) - { - policy.WithOrigins( - "http://localhost:5002", // Food_Ordering_Web - "http://localhost:5003", // Kitchen_Web (if you set it) - "http://localhost:5173" // optional dev server - ) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - } - else - { - policy.WithOrigins("https://restosolutionssaas.com") - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - } + policy.WithOrigins(allowedOrigins) + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); }); }); @@ -70,16 +57,7 @@ // Logging // --------------------------- var logger = app.Services.GetRequiredService>(); -var cs = builder.Configuration.GetConnectionString("MenuDbConnection"); - -if (env.IsDevelopment()) -{ - logger.LogInformation("Using MenuDbConnection: {ConnectionString}", cs); -} -else -{ - logger.LogInformation("MenuDbConnection configured."); -} +logger.LogInformation("MenuDbConnection configured."); // --------------------------- // DB migrations @@ -115,3 +93,20 @@ app.MapControllers(); app.Run(); + +static string[] GetAllowedOrigins(IConfiguration configuration) +{ + var origins = configuration.GetSection("Cors:AllowedOrigins").Get(); + if (origins is { Length: > 0 }) + { + return origins; + } + + var rawOrigins = configuration["Cors:AllowedOrigins"]; + if (!string.IsNullOrWhiteSpace(rawOrigins)) + { + return rawOrigins.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + } + + throw new InvalidOperationException("Cors:AllowedOrigins is missing. Configure it in appsettings or env vars."); +} diff --git a/Order_API/Order_API_appsettings.Development.json b/Order_API/Order_API_appsettings.Development.json index 8d56d7a3..0702b5f1 100644 --- a/Order_API/Order_API_appsettings.Development.json +++ b/Order_API/Order_API_appsettings.Development.json @@ -3,6 +3,15 @@ "ConnectionString": "mongodb://localhost:27017", "DatabaseName": "FoodOrdering" }, + "Cors": { + "AllowedOrigins": [ + "http://localhost:5002", + "http://localhost:5003", + "http://localhost:5173", + "http://localhost:8088", + "http://localhost:8089" + ] + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/Order_API/Order_API_appsettings.json b/Order_API/Order_API_appsettings.json index eb7d968b..3d3bf96f 100644 --- a/Order_API/Order_API_appsettings.json +++ b/Order_API/Order_API_appsettings.json @@ -6,9 +6,13 @@ } }, "MongoDBSettings": { - "ConnectionString": "mongodb://mongodb:NxPostgrsql@docdb-2024-06-22-00-05-00.cluster-cz0qqo02m0na.eu-west-1.docdb.amazonaws.com:27017/?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false", - "DatabaseName": "OrderDb", - + "ConnectionString": "mongodb://your-mongo-host:27017", + "DatabaseName": "OrderDb" + }, + "Cors": { + "AllowedOrigins": [ + "https://your-domain.example" + ] }, "AllowedHosts": "*" } diff --git a/Order_API/Program.cs b/Order_API/Program.cs index 62d62be3..eef9f0b1 100644 --- a/Order_API/Program.cs +++ b/Order_API/Program.cs @@ -41,26 +41,13 @@ // CORS builder.Services.AddCors(options => { + var allowedOrigins = GetAllowedOrigins(builder.Configuration); options.AddPolicy("AllowMyOrigins", policy => { - if (env.IsDevelopment()) - { - policy.WithOrigins( - "http://localhost:5002", - "http://localhost:5003", - "http://localhost:5173" - ) - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - } - else - { - policy.WithOrigins("https://restosolutionssaas.com") - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - } + policy.WithOrigins(allowedOrigins) + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials(); }); }); @@ -70,12 +57,7 @@ var logger = app.Services.GetRequiredService>(); var mongoOptions = app.Services.GetRequiredService>().Value; -if (env.IsDevelopment()) - logger.LogInformation("MongoDBSettings ConnectionString: {ConnectionString}", mongoOptions.ConnectionString); -else - logger.LogInformation("MongoDBSettings configured."); - -logger.LogInformation("MongoDBSettings DatabaseName: {DatabaseName}", mongoOptions.DatabaseName); +logger.LogInformation("MongoDBSettings configured. DatabaseName: {DatabaseName}", mongoOptions.DatabaseName); // Pipeline app.UseSwagger(); @@ -95,3 +77,20 @@ app.MapHub("/api/OrderApi/orderStatusHub"); app.Run(); + +static string[] GetAllowedOrigins(IConfiguration configuration) +{ + var origins = configuration.GetSection("Cors:AllowedOrigins").Get(); + if (origins is { Length: > 0 }) + { + return origins; + } + + var rawOrigins = configuration["Cors:AllowedOrigins"]; + if (!string.IsNullOrWhiteSpace(rawOrigins)) + { + return rawOrigins.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + } + + throw new InvalidOperationException("Cors:AllowedOrigins is missing. Configure it in appsettings or env vars."); +} diff --git a/Restaurant_API/Program.cs b/Restaurant_API/Program.cs index d0660d78..bf583052 100644 --- a/Restaurant_API/Program.cs +++ b/Restaurant_API/Program.cs @@ -42,29 +42,13 @@ // --------------------------- builder.Services.AddCors(options => { + var allowedOrigins = GetAllowedOrigins(builder.Configuration); options.AddPolicy("AllowMyOrigins", policy => { - if (env.IsDevelopment()) - { - policy.WithOrigins( - "http://localhost:5002", // Food_Ordering_Web - "http://localhost:5003", // Kitchen_Web (if you use it) - "http://localhost:5173" // optional dev server - ) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - } - else - { - policy.WithOrigins( - "https://restosolutionssaas.com:8443", - "https://restosolutionssaas.com" - ) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - } + policy.WithOrigins(allowedOrigins) + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); }); }); @@ -74,16 +58,7 @@ // Safe logging // --------------------------- var logger = app.Services.GetRequiredService>(); -var cs = builder.Configuration.GetConnectionString("OutletDbConnection"); - -if (env.IsDevelopment()) -{ - logger.LogInformation("Using OutletDbConnection: {ConnectionString}", cs); -} -else -{ - logger.LogInformation("OutletDbConnection configured."); -} +logger.LogInformation("OutletDbConnection configured."); // --------------------------- // DB migrations @@ -121,3 +96,20 @@ app.MapControllers(); app.Run(); + +static string[] GetAllowedOrigins(IConfiguration configuration) +{ + var origins = configuration.GetSection("Cors:AllowedOrigins").Get(); + if (origins is { Length: > 0 }) + { + return origins; + } + + var rawOrigins = configuration["Cors:AllowedOrigins"]; + if (!string.IsNullOrWhiteSpace(rawOrigins)) + { + return rawOrigins.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + } + + throw new InvalidOperationException("Cors:AllowedOrigins is missing. Configure it in appsettings or env vars."); +} diff --git a/Restaurant_API/Restaurant_API_appsettings.Development.json b/Restaurant_API/Restaurant_API_appsettings.Development.json index 9b28dd7f..72dd38c5 100644 --- a/Restaurant_API/Restaurant_API_appsettings.Development.json +++ b/Restaurant_API/Restaurant_API_appsettings.Development.json @@ -2,6 +2,15 @@ "ConnectionStrings": { "OutletDbConnection": "Host=localhost;Port=5432;Database=OutletDb;User Id=postgres;Password=postgres;" }, + "Cors": { + "AllowedOrigins": [ + "http://localhost:5002", + "http://localhost:5003", + "http://localhost:5173", + "http://localhost:8088", + "http://localhost:8089" + ] + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/Restaurant_API/Restaurant_API_appsettings.json b/Restaurant_API/Restaurant_API_appsettings.json index 3deb6928..84a3ed2b 100644 --- a/Restaurant_API/Restaurant_API_appsettings.json +++ b/Restaurant_API/Restaurant_API_appsettings.json @@ -1,21 +1,26 @@ { "ConnectionStrings": { - "OutletDbConnection": "Host=restaurantapi.cz0qqo02m0na.eu-west-1.rds.amazonaws.com;Port=5432;Database=OutletDb;User Id=postgres;Password=NxPostgrsql;" + "OutletDbConnection": "Host=your-db-host;Port=5432;Database=OutletDb;Username=postgres;Password=change-me;" + }, + "Cors": { + "AllowedOrigins": [ + "https://your-domain.example" + ] }, "StripeSettings": { - "ApiKey": "sk_test_51NjhBQFU6tKdw4REQ4sdK5t4EUN3aNkvW7Z3v9e41eXjEgfHwcnFztdPvwrRIFeGgwuMpzvkrcn8CSghhoCbJS9S006L3W13JP", - "WebhookSecret": "pk_test_51NjhBQFU6tKdw4RE8kO4funmhbcbtQur1zsSD3YNbNBBAYQRZqR1omJtSp4KesSL3eHKPr03uZnuCoWUK233DYvD00wd9n7wfQ" + "ApiKey": "change-me", + "WebhookSecret": "change-me" }, "EmailSettings": { "Host": "smtp.gmail.com", "Port": 587, - "Email": "sitewebsite73@gmail.com", - "Password": "otrzdbifusqsiuoc" + "Email": "change-me@example.com", + "Password": "change-me" }, "Authentication": { "Google": { - "ClientId": "247244252156-cqtuh8m6k4s6mcumhkri2grnkf5g5a8d.apps.googleusercontent.com", - "ClientSecret": "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" + "ClientId": "change-me", + "ClientSecret": "change-me" } }, "Logging": { diff --git a/docker-compose.yml b/docker-compose.yml index 82f9a59f..47f8ee42 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,8 @@ services: image: postgres:16 container_name: food-postgres environment: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres + POSTGRES_USER: ${POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} ports: - "5432:5432" volumes: @@ -37,11 +37,11 @@ services: environment: ASPNETCORE_ENVIRONMENT: Development ASPNETCORE_URLS: http://+:80 - ConnectionStrings__ApplicationDbConnection: Host=postgres;Port=5432;Database=ApplicationDb;Username=postgres;Password=postgres - ApplicationDbConnection: Host=postgres;Port=5432;Database=ApplicationDb;Username=postgres;Password=postgres - Jwt__Key: dev-super-secret-key - Jwt__Issuer: dev - Jwt__Audience: dev + ConnectionStrings__ApplicationDbConnection: ${APPLICATION_DB_CONNECTION:-Host=postgres;Port=5432;Database=ApplicationDb;Username=postgres;Password=postgres} + Jwt__Key: ${JWT_KEY:-dev-super-secret-key} + Jwt__Issuer: ${JWT_ISSUER:-dev} + Jwt__Audience: ${JWT_AUDIENCE:-dev} + Cors__AllowedOrigins: ${ALLOWED_ORIGINS:-http://localhost:8088,http://localhost:8089} depends_on: postgres: condition: service_healthy @@ -56,8 +56,8 @@ services: environment: ASPNETCORE_ENVIRONMENT: Development ASPNETCORE_URLS: http://+:80 - ConnectionStrings__OutletDbConnection: Host=postgres;Port=5432;Database=OutletDb;Username=postgres;Password=postgres - OutletDbConnection: Host=postgres;Port=5432;Database=OutletDb;Username=postgres;Password=postgres + ConnectionStrings__OutletDbConnection: ${OUTLET_DB_CONNECTION:-Host=postgres;Port=5432;Database=OutletDb;Username=postgres;Password=postgres} + Cors__AllowedOrigins: ${ALLOWED_ORIGINS:-http://localhost:8088,http://localhost:8089} depends_on: postgres: condition: service_healthy @@ -72,8 +72,8 @@ services: environment: ASPNETCORE_ENVIRONMENT: Development ASPNETCORE_URLS: http://+:80 - ConnectionStrings__MenuDbConnection: Host=postgres;Port=5432;Database=MenuDb;Username=postgres;Password=postgres - MenuDbConnection: Host=postgres;Port=5432;Database=MenuDb;Username=postgres;Password=postgres + ConnectionStrings__MenuDbConnection: ${MENU_DB_CONNECTION:-Host=postgres;Port=5432;Database=MenuDb;Username=postgres;Password=postgres} + Cors__AllowedOrigins: ${ALLOWED_ORIGINS:-http://localhost:8088,http://localhost:8089} depends_on: postgres: condition: service_healthy @@ -88,8 +88,9 @@ services: environment: ASPNETCORE_ENVIRONMENT: Development ASPNETCORE_URLS: http://+:80 - MongoDBSettings__ConnectionString: mongodb://mongo:27017 - MongoDBSettings__DatabaseName: FoodOrdering + MongoDBSettings__ConnectionString: ${MONGO_CONNECTION_STRING:-mongodb://mongo:27017} + MongoDBSettings__DatabaseName: ${MONGO_DATABASE:-FoodOrdering} + Cors__AllowedOrigins: ${ALLOWED_ORIGINS:-http://localhost:8088,http://localhost:8089} depends_on: mongo: condition: service_healthy @@ -104,8 +105,8 @@ services: environment: ASPNETCORE_ENVIRONMENT: Development ASPNETCORE_URLS: http://+:80 - ApiBaseUrl: http://food-ordering-api/ - RestaurantApiBaseUrl: http://restaurant-api/ + ApiBaseUrl: ${FOOD_ORDERING_API_BASE_URL:-http://food-ordering-api/} + RestaurantApiBaseUrl: ${RESTAURANT_API_BASE_URL:-http://restaurant-api/} depends_on: - food-ordering-api - restaurant-api @@ -122,10 +123,11 @@ services: environment: ASPNETCORE_ENVIRONMENT: Development ASPNETCORE_URLS: http://+:80 - ApiBaseUrl: http://food-ordering-api/ - Jwt__Key: dev-super-secret-key - Jwt__Issuer: dev - Jwt__Audience: dev + ApiBaseUrl: ${FOOD_ORDERING_API_BASE_URL:-http://food-ordering-api/} + Jwt__Key: ${JWT_KEY:-dev-super-secret-key} + Jwt__Issuer: ${JWT_ISSUER:-dev} + Jwt__Audience: ${JWT_AUDIENCE:-dev} + Cors__AllowedOrigins: ${ALLOWED_ORIGINS:-http://localhost:8088,http://localhost:8089} depends_on: - food-ordering-api ports: