diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 517ce04..b29450e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -103,6 +103,8 @@ jobs: --name qrrapido-staging \ --restart unless-stopped \ -p 5000:8080 \ + --add-host=host.docker.internal:host-gateway \ + -e Serilog__SeqUrl="http://host.docker.internal:5343" \ -e ASPNETCORE_ENVIRONMENT=Staging \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop EOF @@ -124,6 +126,8 @@ jobs: --name qrrapido-staging \ --restart unless-stopped \ -p 5000:8080 \ + --add-host=host.docker.internal:host-gateway \ + -e Serilog__SeqUrl="http://host.docker.internal:5342" \ -e ASPNETCORE_ENVIRONMENT=Staging \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop EOF diff --git a/Middleware/LanguageRedirectionMiddleware.cs b/Middleware/LanguageRedirectionMiddleware.cs index 98540c3..9f99784 100644 --- a/Middleware/LanguageRedirectionMiddleware.cs +++ b/Middleware/LanguageRedirectionMiddleware.cs @@ -6,7 +6,7 @@ namespace QRRapidoApp.Middleware { private readonly RequestDelegate _next; private readonly ILogger _logger; - private readonly string[] _supportedCultures = { "pt-BR", "es-PY", "es" }; + private readonly string[] _supportedCultures = { "pt-BR", "es-PY" }; private const string DefaultCulture = "pt-BR"; public LanguageRedirectionMiddleware(RequestDelegate next, ILogger logger) @@ -18,31 +18,34 @@ namespace QRRapidoApp.Middleware public async Task InvokeAsync(HttpContext context) { var path = context.Request.Path.Value?.TrimStart('/') ?? ""; - - // Skip if already has culture in path, or if it's an API, static file, or special route + if (HasCultureInPath(path) || IsSpecialRoute(path)) { await _next(context); return; } - // Detect browser language var detectedCulture = DetectBrowserLanguage(context); - - // Build redirect URL with culture + + // If the detected culture is the default, do not redirect. + if (detectedCulture == DefaultCulture) + { + await _next(context); + return; + } + var redirectUrl = $"/{detectedCulture}"; if (!string.IsNullOrEmpty(path)) { redirectUrl += $"/{path}"; } - - // Add query string if present + if (context.Request.QueryString.HasValue) { redirectUrl += context.Request.QueryString.Value; } - _logger.LogInformation("Redirecting to localized URL: {RedirectUrl} (detected culture: {Culture})", + _logger.LogInformation("Redirecting to localized URL: {RedirectUrl} (detected culture: {Culture})", redirectUrl, detectedCulture); context.Response.Redirect(redirectUrl, permanent: false); @@ -64,7 +67,7 @@ namespace QRRapidoApp.Middleware { var specialRoutes = new[] { - "api/", "health", "_framework/", "lib/", "css/", "js/", "images/", + "api/", "health", "_framework/", "lib/", "css/", "js/", "images/", "favicon.ico", "robots.txt", "sitemap.xml", "signin-microsoft", "signin-google", "signout-callback-oidc", "Account/ExternalLoginCallback", "Account/Logout", "Pagamento/CreateCheckout", @@ -80,41 +83,30 @@ namespace QRRapidoApp.Middleware if (acceptLanguage != null && acceptLanguage.Any()) { - // Check for exact matches first foreach (var lang in acceptLanguage.OrderByDescending(x => x.Quality ?? 1.0)) { var langCode = lang.Value.Value; - // Special case: es-PY should redirect to pt-BR + // Exact match for es-PY if (string.Equals(langCode, "es-PY", StringComparison.OrdinalIgnoreCase)) { - return DefaultCulture; + return "es-PY"; } - // Check exact match - if (_supportedCultures.Contains(langCode)) - { - return langCode; - } - - // Check language part only (e.g., 'es' from 'es-AR') - var languagePart = langCode.Split('-')[0]; - - // Map 'es' to 'es-PY' specifically - if (string.Equals(languagePart, "es", StringComparison.OrdinalIgnoreCase)) + // Generic 'es' maps to 'es-PY' + if (langCode.StartsWith("es-", StringComparison.OrdinalIgnoreCase) || string.Equals(langCode, "es", StringComparison.OrdinalIgnoreCase)) { return "es-PY"; } - var matchingCulture = _supportedCultures.FirstOrDefault(c => c.StartsWith(languagePart + "-") || c == languagePart); - if (matchingCulture != null) + // Check for pt-BR + if (langCode.StartsWith("pt-", StringComparison.OrdinalIgnoreCase) || string.Equals(langCode, "pt", StringComparison.OrdinalIgnoreCase)) { - return matchingCulture; + return "pt-BR"; } } } - // Default fallback return DefaultCulture; } } diff --git a/Program.cs b/Program.cs index eaa56a2..04559ca 100644 --- a/Program.cs +++ b/Program.cs @@ -147,7 +147,6 @@ builder.Services.Configure(options => { new CultureInfo("pt-BR"), new CultureInfo("es-PY"), - new CultureInfo("es") }; options.DefaultRequestCulture = new RequestCulture("pt-BR", "pt-BR"); @@ -284,7 +283,7 @@ app.MapHealthChecks("/healthcheck"); // Language routes (must be first) app.MapControllerRoute( name: "localized", - pattern: "{culture:regex(^(pt-BR|es-PY|es)$)}/{controller=Home}/{action=Index}/{id?}"); + pattern: "{culture:regex(^(es-PY)$)}/{controller=Home}/{action=Index}/{id?}"); // API routes app.MapControllerRoute( diff --git a/Views/Home/Index.cshtml b/Views/Home/Index.cshtml index 3639918..64b491b 100644 --- a/Views/Home/Index.cshtml +++ b/Views/Home/Index.cshtml @@ -137,6 +137,23 @@ +
+
+
+ +
+
+
+
+ +
+
+
+