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/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/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 5719ef2..577d4e5 100644 --- a/backend/appsettings.json +++ b/backend/appsettings.json @@ -5,6 +5,12 @@ "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" + }, + "AllowedConfig": { + "Origins": "https://cs-chat-frondend.onrender.com" + }, "AllowedHosts": "*", "JwtSettings": { "Secret": "123456789101112131415161718192021222324252627282930", 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(); } 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");