WIP add devs files for working with caddy / mercure

This commit is contained in:
Julien Fastré 2025-07-16 10:56:52 +02:00
parent def75cec6c
commit 3aea3f502b
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
5 changed files with 48 additions and 2 deletions

View File

@ -36,5 +36,5 @@ services:
###> symfony/mercure-bundle ###
mercure:
ports:
- "127.0.0.1:8080:80"
- "127.0.0.1:8043:443"
###< symfony/mercure-bundle ###

View File

@ -61,7 +61,7 @@ services:
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
# Set the URL of your Symfony project (without trailing slash!) as value of the cors_origins directive
MERCURE_EXTRA_DIRECTIVES: |
cors_origins http://127.0.0.1:8000
cors_origins http://chill-bundles.wip https://chill-bundles.wip
# Comment the following line to disable the development mode
command: /usr/bin/caddy run --config /etc/caddy/dev.Caddyfile
healthcheck:

View File

@ -17,3 +17,8 @@ when@dev:
defaults:
template: '@ChillMain/Dev/dev.assets.test2.html.twig'
dev_mercure:
path: /_dev/mercure
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: '@ChillMain/Dev/dev.mercure.html.twig'

20
resources/dev.Caddyfile Normal file
View File

@ -0,0 +1,20 @@
{
# Désactive les redirections automatiques HTTP -> HTTPS
# auto_https off
# Désactive le port 80 par défaut
# default_bind :8080
}
localhost:8043 {
mercure {
# Publisher JWT key
publisher_jwt !ChangeThisMercureHubJWTSecretKey!
# Subscriber JWT key
subscriber_jwt !ChangeThisMercureHubJWTSecretKey!
cors_origins http://chill-bundles.wip https://chill-bundles.wip
ui
demo
}
respond "Not Found" 404
}

View File

@ -0,0 +1,21 @@
<html>
<head>
<title>Test mercure</title>
</head>
<body>
<form method="GET">
<input type="text" name="eventSource" value="" />
<button type="submit" name="submit" value="Submit">Submit</button>
</form>
<script>
{% if app.request.query.has('eventSource') %}
const eventSource = new EventSource("{{ mercure(app.request.query.get('eventSource'))|escape('js') }}");
eventSource.onmessage = event => {
// Will be called every time an update is published by the server
console.log(JSON.parse(event.data));
}
{% endif %}
</script>
</body>
</html>