flovntp / bigfoot-workshop-with-api-mercure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mercure Platform.sh Template

Mercure is an open protocol for real-time communications designed to be fast, reliable and battery-efficient. It is a modern and convenient replacement for both the Websocket API and the higher-level libraries and services relying on it.

Mercure is especially useful to add streaming capabilities to REST and GraphQL APIs. Because it is a thin layer on top of HTTP and SSE, Mercure is natively supported by modern web browsers, mobile applications and IoT devices.

See https://mercure.rocks.

Make sure you change in .platform/applications.yaml

MERCURE_PUBLISHER_JWT_KEY='!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY='!ChangeMe!'

You probably also want to disable the demo/ui in: mercure/Caddyfile.platform_sh and possibly allowing anonymous users.

Copyright

For Mercure: Kévin Dunglas, all rights reserved.

How this example was built:

Installation

$MERCURE_VERSION="0.14.0"
wget https://github.com/dunglas/mercure/releases/download/v{$MERCURE_VERSION}/mercure_{$MERCURE_VERSION}_Linux_x86_64.tar.gz
gunzip mercure_{$MERCURE_VERSION}_Linux_x86_64.tar.gz
tar xvf mercure_{$MERCURE_VERSION}_Linux_x86_64.tar

Add mount for DB (you can also use postgres etc..)

.platform.app.yaml

mounts:
    'db':
        source: local
        source_path: db

Make sure caching are request buffering are off

.platform/routes.yaml

"https://mercure.{default}/":
    type: upstream
    upstream: "mercure:http"
    cache:
        enabled: false

Andin .platform.app.yaml

        locations:
            /:
                allow: false
                passthru: true
                request_buffering:
                  enabled: false

Configuration (in the variables.env section:)

SERVER_NAME=:$PORT
MERCURE_PUBLISHER_JWT_KEY='!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY='!ChangeMe!'

Start command

./mercure run -config Caddyfile.platform_sh

About