Ошибка Symfony Не удалось подключиться к серверу для "http://localhost:3000/.well-known/mercure"

У меня проблема с использованием ртути в проекте Symfony, я установил ртуть в корень своего проекта, однако, когда я тестирую отправку запроса в ртуть, я получил ошибку

Не удалось подключиться к серверу для "http://localhost:3000/.well-known/mercury"

Хотя URL-адрес http: // localhost:3000/.well-known / mercury легко доступен локально.

Конфигурация .env.local:

MERCURE_PUBLISH_URL=http://localhost:3000/.well-known/mercure
MERCURE_JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdfX0.obDjwCgqtPuIvwBlTxUEmibbBf0zypKCNzNKP7Op2UM

конфигурация .env:

###> symfony/mercure-bundle ###
# See https://symfony.com/doc/current/mercure.html#configuration
MERCURE_PUBLISH_URL=http://localhost:3000/.well-known/mercure
# The default token is signed with the secret key: !ChangeMe!
MERCURE_JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdfX0.obDjwCgqtPuIvwBlTxUEmibbBf0zypKCNzNKP7Op2UM
###< symfony/mercure-bundle ###

token JWT через JWT.io:

Команда Mercure:

./mercure --jwt-key='!ChangeMe!' --addr='localhost:3000' --allow-anonymous --cors-allowed-origins='*'

Мой контроллер:

<?php
 
namespace App\Controller;
 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mercure\PublisherInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Routing\Annotation\Route;
 
/**
 * Class InterestController
 * @package App\Controller
 */
class InterestController extends AbstractController
{
 
    /**
     * @Route("/profil/{user_id}/interets", name="user_interests", requirements={"user_id":"\d+"})
     * @ParamConverter("user", options={"mapping": {"user_id" : "id"}})
     * @ParamConverter("profil", options={"mapping": {"user_id" : "user_id"}})
     */
    public function index()
    {
        return $this->render('interest/index.html.twig', [
            'controller_name' => 'InterestController',
        ]);
    }
 
    /**
     * @Route("/ping", name="ping", methods={"POST"})
     * @param PublisherInterface $publisher
     * @return Response
     */
    public function __invoke(PublisherInterface $publisher): Response
    {
        $update = new Update(
            'http://monsite.com/ping',
            json_encode(['status' => 'OutOfStock'])
        );
 
        // The Publisher service is an invokable object
        $publisher($update);
 
        return new Response('published!');
    }
}

Тестовый фронт:

{% extends 'base.html.twig' %}
{% block body %}
    <form id="interest-form" action="{{ path('ping') }}" method="POST">
        <a  href="javascript:{}" onclick="document.getElementById('interest-form').submit();" class="send-interest">
        </a>
    </form>
{% endblock %}
{% block javascripts %}
    <script>
        // URL is a built-in JavaScript class to manipulate URLs
        const eventSource = new EventSource('http://localhost:3000/.well-known/mercure?topic=' + encodeURIComponent('http://monsite.com/ping'));
        eventSource.onmessage = event => {
            // Will be called every time an update is published by the server
            console.log(JSON.parse(event.data));
        }
    </script>
{% endblock %}

Сообщение об ошибке:

0 ответов

Другие вопросы по тегам