Skip to content
Merged

Dev #2408

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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using System;
Expand All @@ -16,7 +17,6 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;
using Volo.Abp.SettingManagement;
using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Users;

namespace Unity.Notifications.EmailNotifications;
Expand All @@ -29,7 +29,7 @@ public class EmailNotificationService(
IExternalUserLookupServiceProvider externalUserLookupServiceProvider,
ISettingManager settingManager,
IFeatureChecker featureChecker,
IAppUrlProvider appUrlProvider) : ApplicationService, IEmailNotificationService
IHttpContextAccessor httpContextAccessor) : ApplicationService, IEmailNotificationService
{

public async Task<Guid> InitializeDraftAsync(Guid applicationId)
Expand Down Expand Up @@ -72,10 +72,24 @@ protected virtual async Task NotifyTeamsChannel(string chesEmailError)
await notificationAppService.PostToTeamsAsync(activityTitle, activitySubtitle);
}

public async Task<string> GetBaseUrlAsync()
public Task<string> GetBaseUrlAsync()
{
var appUrl = await appUrlProvider.GetUrlAsync(appName: "MVC");
return appUrl;
var httpContext = httpContextAccessor.HttpContext
?? throw new InvalidOperationException("No active HTTP context available to resolve base URL.");

var request = httpContext.Request;

var host = request.Headers["X-Forwarded-Host"].FirstOrDefault()
?? request.Host.Value;

var scheme = request.Headers["X-Forwarded-Proto"].FirstOrDefault()
?? request.Scheme;

var pathBase = request.Headers["X-Forwarded-Prefix"].FirstOrDefault()
?? request.PathBase.Value
?? string.Empty;

return Task.FromResult($"{scheme}://{host}{pathBase}".TrimEnd('/'));
}

public async Task<HttpResponseMessage> SendCommentNotification(EmailCommentDto input)
Expand Down
Loading