Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 11 additions & 6 deletions Food_Ordering_API/Food_Ordering_API_appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
}
44 changes: 22 additions & 22 deletions Food_Ordering_API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,20 @@
// 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();
});
});

var app = builder.Build();

// Logging + migrations
var logger = app.Services.GetRequiredService<ILogger<Program>>();
var cs = builder.Configuration.GetConnectionString("ApplicationDbConnection");
logger.LogInformation("ApplicationDbConnection configured.");

using (var scope = app.Services.CreateScope())
Expand Down Expand Up @@ -148,3 +131,20 @@
app.MapControllers();

app.Run();

static string[] GetAllowedOrigins(IConfiguration configuration)
{
var origins = configuration.GetSection("Cors:AllowedOrigins").Get<string[]>();
if (origins is { Length: > 0 })
{
return origins;
Comment on lines +135 to +140
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split comma-separated CORS env var before returning

When Cors:AllowedOrigins is set via env (as in docker-compose.yml/.env with a comma-separated list), Get<string[]>() binds it as a single-element array containing the entire string (e.g., "http://localhost:8088,http://localhost:8089"). Because the code returns early on Length > 0, the comma-split fallback never runs, and WithOrigins(...) receives an invalid origin containing a comma, which throws at startup in the default docker-compose configuration. Consider checking for a single entry that contains commas and splitting before returning, or prefer the raw string split when the value comes from env.

Useful? React with 👍 / 👎.

}

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.");
}
24 changes: 12 additions & 12 deletions Food_Ordering_Web/appsettings.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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": "*"
}
9 changes: 9 additions & 0 deletions Kitchen_Web/Kitchen_Web_appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 14 additions & 9 deletions Kitchen_Web/Kitchen_Web_appsettings.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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": "*"
}
40 changes: 22 additions & 18 deletions Kitchen_Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down Expand Up @@ -156,3 +143,20 @@
app.MapControllers();

app.Run();

static string[] GetAllowedOrigins(IConfiguration configuration)
{
var origins = configuration.GetSection("Cors:AllowedOrigins").Get<string[]>();
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.");
}
9 changes: 9 additions & 0 deletions Menu_API/Menu_API_appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions Menu_API/Menu_API_appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
}
}
Loading
Loading