live-source-proxy

0.1.10 • Public • Published

live-source-proxy

NPM version

If you want to use live-source in a browser, you probably need this, because:

  1. CORS stops lots of fetches you might want to do
  2. Your server probably is in a better position to poll, if necessary
  3. Your server can get webhook calls, which clients can't

Think of this as two related modules 'live-source-proxy/client' and 'live-source-proxy/server'. You probably only want to require one or the other, and the server one wont load in a browser. We have them in one package to simplify our work in developing them.


Set up a server

Something like this:

$ npm i -g live-source-proxy
...
$ PORT=3000 SITEURL=https://myproxy.example/proxy pm2 start live-source-proxy

and edit your nginx config to include a line like:

location /proxy/ { proxy_pass http://127.0.0.1:3000/; }

Then, down below, put the string https://myproxy.example/proxy as ADDRESS_OF_YOUR_SERVER.

Depending on the live-source modules you use, you may have a lot more configuration and authentication setup to do.

Use it from clients

Install live-source-proxy instead of live-source:

$ npm i live-source-proxy

Code is the same after setup:

const client = require('live-source-proxy/client')
const livesource = client('ADDRESS_OF_YOUR_SERVER') // customize this
 
// use it just like you'd use require('live-source')
 const doc = livesource.open('https://time.hawke.org/')
 doc.on('change', () => console.log(doc.text))
 setTimeout(() => livesource.closeAll(), 5000)

Then browserify your code and run it in browsers.

In theory, you could get the address from document.location.origin. I'm not sure how often these things will really be served from the same server, though.

Readme

Keywords

Package Sidebar

Install

npm i live-source-proxy

Weekly Downloads

1

Version

0.1.10

License

MIT

Unpacked Size

12.5 kB

Total Files

6

Last publish

Collaborators

  • sandhawke