Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A open reverse proxy allowing to poll JSON REST APIs and push updates to clients by utilizing Server-Sent Events (SSE)

License

NotificationsYou must be signed in to change notification settings

fschaefer/event-stream-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

event-stream-proxy is a open reverse proxy allowing you to poll JSON REST APIs and push updates to clients by utilizingServer-Sent Events (SSE), heavily inspired byStreamdata.io

Features

  • Incremental data updates: depending on selected operation mode, only changed data is sent to clients via JSON-Patch(RFC6902)
  • Push: updates are pushed to the client using Server-Sent Events (SSE). By providingfallback mechanisms this also works with older browsers.
  • Transparent: all query parameters and (some) HTTP headers are passed through to the upstream server.
  • Configurable: either by environment variables or per request via special HTTP headers

Example

Fire up the proxy vianpm:

# install modules:$> npm install[...]# run TypeScript compiler:$> npm run-script build[...]# run proxy:$> npm run-script start> event-stream-proxy@1.0.0 start /projects/event-stream-proxy> node.[12:38:07.094] [LOG]   Server running at http://127.0.0.1:3001/[12:38:10.434] [LOG]   A client is subscribing to SSE streamfor"http://date.jsontest.com/"in mode"patch".[12:38:10.439] [LOG]   Starting server-sent event streamfor"http://date.jsontest.com/" at a 10 seconds poll interval.[12:38:15.970] [LOG]   A client is unsubscribing from SSE streamfor"http://date.jsontest.com/".[12:38:15.973] [LOG]   Stopping server-sent event streamfor"http://date.jsontest.com/".

and do a request viacurl

$> curl http://127.0.0.1:3001/http://date.jsontest.com/event:datadata:{"time":"11:29:52 AM","milliseconds_since_epoch":1511350192851,"date":"11-22-2017"}event:patchdata:[{"op":"replace","path":"/milliseconds_since_epoch","value":1511350203061},{"op":"replace","path":"/time","value":"11:30:03 AM"}]:event:patchdata:[{"op":"replace","path":"/milliseconds_since_epoch","value":1511350213328},{"op":"replace","path":"/time","value":"11:30:13 AM"}]event:patchdata:[{"op":"replace","path":"/milliseconds_since_epoch","value":1511350223537},{"op":"replace","path":"/time","value":"11:30:23 AM"}]

Configuration

The proxy is either configured by environment variables and / or HTTP headers.

The environment variables are:

  • npm_package_config_HOST : The host (default - "127.0.0.1") ...
  • npm_package_config_PORT : ... and port (default - "3001") the proxy listens on.
  • npm_pacakge_config_MODE : The default operation mode:
    • "patch" : utilize JSON-Patch and only send diffs to the client, or
    • "data" : to send the whole new data on updates.
  • npm_package_config_PING_INTERVAL : The interval in seconds (default - "20") the client receives ping messages, to keep the stream open.
  • npm_package_config_REFRESH_INTERVAL : The interval in seconds (default - "10") the upstream server is polled with.
  • npm_package_config_PASS_HEADERS : The headers that are passed through to upstream server (default - "auth-header,authorization")

The MODE, PING_INTERVAL and REFRESH_INTERVAL can also be configured per client with the corresponding HTTP headers "esp-mode", "esp-ping-interval" and "esp-refresh-interval". The configuration via environment variables forms the lower limit, so the clients can't bring on lower intervals.

License

See license file.

About

A open reverse proxy allowing to poll JSON REST APIs and push updates to clients by utilizing Server-Sent Events (SSE)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp