change to dynamic ur

This commit is contained in:
Charles 2026-02-10 11:49:04 +01:00
parent 856e51ff09
commit 455d71693d
5 changed files with 12 additions and 4 deletions

View File

@ -4,7 +4,8 @@ export default class extends Controller {
static targets = ['badge', 'list'];
static values = {
userId: Number,
mercureUrl: String
mercureUrl: String,
url: String,
};
connect() {
@ -39,7 +40,7 @@ export default class extends Controller {
// Use server-provided topic if available, otherwise fallback to default per-user topic
const topic = data.topic || `http://portail.solutions-easy.moi/notifications/user/${this.userIdValue}`;
const topic = data.topic || `${this.urlValue}/notifications/user/${this.userIdValue}`;
const url = new URL(this.mercureUrlValue);
url.searchParams.append('topic', topic);

View File

@ -5,6 +5,7 @@ twig:
globals:
application: '%env(APPLICATION)%'
aws_url: '%env(AWS_S3_PORTAL_URL)%'
app_url: '%env(APP_URL)%'
version: '0.5'
paths:

View File

@ -7,6 +7,7 @@ parameters:
aws_url: '%env(AWS_ENDPOINT)%'
aws_public_url: '%env(AWS_ENDPOINT)%'
aws_bucket: '%env(S3_PORTAL_BUCKET)%'
app_url: '%env(APP_URL)%'
mercure_secret: '%env(MERCURE_JWT_SECRET)%'
logos_directory: '%kernel.project_dir%/public/uploads/logos'
@ -24,6 +25,9 @@ services:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
App\MessageHandler\NotificationMessageHandler:
arguments:
$appUrl: '%app_url%'
App\EventSubscriber\:
resource: '../src/EventSubscriber/'
tags: ['kernel.event_subscriber']

View File

@ -16,7 +16,8 @@ class NotificationMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly HubInterface $hub
private readonly HubInterface $hub,
private string $appUrl
) {
}
@ -48,7 +49,7 @@ class NotificationMessageHandler
private function publishToMercure(Notification $notification): void
{
$topic = sprintf('http://portail.solutions-easy.moi/notifications/user/%d', $notification->getUser()->getId());
$topic = sprintf('%s/notifications/user/%d', $this->appUrl, $notification->getUser()->getId());
$update = new Update(
$topic,

View File

@ -43,6 +43,7 @@
<li class="nav-item dropdown nav-notif"
data-controller="notification"
data-notification-user-id-value="{{ app.user.id }}"
data-notification-url-value="{{ app_url }}"
data-notification-mercure-url-value="{{ app.request.server.get('MERCURE_PUBLIC_URL') ?: 'http://mercure.solutions-easy.moi/.well-known/mercure' }}">
<a id="notificationDropdown"
class="nav-link count-indicator dropdown-toggle m-auto"