From 66f9677b98d7d81bb83bb34cc1fec2d473d0c192 Mon Sep 17 00:00:00 2001 From: Matheus Res Date: Fri, 18 Jul 2025 10:47:17 -0300 Subject: [PATCH 1/4] feat: add docker image --- backend/Dockerfile | 18 ++++++++++++++++++ backend/appsettings.json | 3 +++ 2 files changed, 21 insertions(+) create mode 100644 backend/Dockerfile diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..14e6da1 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /App + +# Copy everything +COPY . ./ +# Restore as distinct layers +RUN dotnet restore +# Build and publish a release +RUN dotnet publish -o out + +# Build runtime image +FROM mcr.microsoft.com/dotnet/aspnet:8.0 +ENV ASPNETCORE_HTTP_PORTS=5001 +EXPOSE 5001 +WORKDIR /App +COPY --from=build /App/out . + +ENTRYPOINT ["dotnet", "backend.dll"] diff --git a/backend/appsettings.json b/backend/appsettings.json index 5719ef2..8c77d34 100644 --- a/backend/appsettings.json +++ b/backend/appsettings.json @@ -5,6 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, + "ConnectionStrings": { + "DefaultConnection": "User Id=postgres.qkrcjdvyhdtoxbppdfrd;Password=senha-do-chat;Server=aws-0-sa-east-1.pooler.supabase.com;Port=5432;Database=postgres" + }, "AllowedHosts": "*", "JwtSettings": { "Secret": "123456789101112131415161718192021222324252627282930", From 173da29da52d9732a3e714d17f610e7a7fc7790d Mon Sep 17 00:00:00 2001 From: Matheus Res Date: Fri, 18 Jul 2025 11:08:34 -0300 Subject: [PATCH 2/4] add config to origin --- backend/Configs/AllowedConfig.cs | 7 +++++++ backend/Program.cs | 4 +++- backend/appsettings.Development.json | 3 +++ backend/appsettings.json | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 backend/Configs/AllowedConfig.cs diff --git a/backend/Configs/AllowedConfig.cs b/backend/Configs/AllowedConfig.cs new file mode 100644 index 0000000..9eab7c4 --- /dev/null +++ b/backend/Configs/AllowedConfig.cs @@ -0,0 +1,7 @@ +namespace backend.Configs +{ + public class AllowedConfig + { + public string Origins { get; set; } + } +} \ No newline at end of file diff --git a/backend/Program.cs b/backend/Program.cs index 027bb63..f157de7 100644 --- a/backend/Program.cs +++ b/backend/Program.cs @@ -21,7 +21,9 @@ builder.Services.AddSignalR(); builder.Services.Configure(builder.Configuration.GetSection("JwtSettings")); +builder.Services.Configure(builder.Configuration.GetSection("AllowedConfig")); var jwtSettings = builder.Configuration.GetSection("JwtSettings").Get(); +var allowedConfig = builder.Configuration.GetSection("AllowedConfig").Get(); builder.Services.AddDbContext(options => options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); @@ -90,7 +92,7 @@ { cors.AllowAnyHeader() .AllowAnyMethod() - .AllowCredentials().WithOrigins("http://localhost:8080"); + .AllowCredentials().WithOrigins(allowedConfig.Origins); }); app.UseHttpsRedirection(); diff --git a/backend/appsettings.Development.json b/backend/appsettings.Development.json index 8f7e31a..a7a06ff 100644 --- a/backend/appsettings.Development.json +++ b/backend/appsettings.Development.json @@ -8,6 +8,9 @@ "ConnectionStrings": { "DefaultConnection": "User Id=postgres.qkrcjdvyhdtoxbppdfrd;Password=senha-do-chat;Server=aws-0-sa-east-1.pooler.supabase.com;Port=5432;Database=postgres" }, + "AllowedConfig": { + "Origins": "http://localhost:8080" + }, "JwtSettings": { "Secret": "123456789101112131415161718192021222324252627282930", "Issuer": "https://localhost:5000", diff --git a/backend/appsettings.json b/backend/appsettings.json index 8c77d34..577d4e5 100644 --- a/backend/appsettings.json +++ b/backend/appsettings.json @@ -8,6 +8,9 @@ "ConnectionStrings": { "DefaultConnection": "User Id=postgres.qkrcjdvyhdtoxbppdfrd;Password=senha-do-chat;Server=aws-0-sa-east-1.pooler.supabase.com;Port=5432;Database=postgres" }, + "AllowedConfig": { + "Origins": "https://cs-chat-frondend.onrender.com" + }, "AllowedHosts": "*", "JwtSettings": { "Secret": "123456789101112131415161718192021222324252627282930", From b893cd078cb35a1949f8d3f71cb0c1425cd35cfe Mon Sep 17 00:00:00 2001 From: Matheus Res Date: Fri, 18 Jul 2025 11:15:24 -0300 Subject: [PATCH 3/4] fix: hub connection url --- frontend/src/Hub.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Hub.js b/frontend/src/Hub.js index 7d0c468..2af17d0 100644 --- a/frontend/src/Hub.js +++ b/frontend/src/Hub.js @@ -5,7 +5,7 @@ export default class Hub { this.loginToken = localStorage.getItem('@auth'); this.connection = new HubConnectionBuilder() - .withUrl('http://localhost:5136/Hub', { accessTokenFactory: () => this.loginToken }) + .withUrl(process.env.VUE_APP_API_URL + '/Hub', { accessTokenFactory: () => this.loginToken }) .configureLogging(LogLevel.Information) .build(); } From f96117b136fe19255303d9d396e65e2b58f41815 Mon Sep 17 00:00:00 2001 From: Matheus Res Date: Fri, 18 Jul 2025 11:18:25 -0300 Subject: [PATCH 4/4] fix: api url --- frontend/src/plugins/axios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/plugins/axios.js b/frontend/src/plugins/axios.js index a086b85..18069d2 100644 --- a/frontend/src/plugins/axios.js +++ b/frontend/src/plugins/axios.js @@ -1,6 +1,6 @@ import axios from "axios"; -axios.defaults.baseURL = process.env.VUE_APP_API_URL; +axios.defaults.baseURL = process.env.VUE_APP_API_URL + "/api"; axios.interceptors.request.use( (config) => { const token = localStorage.getItem("@auth");