UNPKG

swish-http

Version:

A Swish implementation that tunnels over HTTP

42 lines (25 loc) 1.33 kB
# Swish HTTP This module provides a Swish store in the browser that forwards requests over HTTP to a Swish store on the server. ## In the browser The file `client.js` can be included on its own (where it will register the global class `SwishHttp`). If used from AMD or CommonJS it will define a module, e.g. ```javascript var SwishHttp = require('swish-http/client'); ``` To set up a store, provide the URL endpoint: ```javascript var store = new SwishHttp('/json/my-store'); ``` ## On the server The main module (`index.js`) provides the counterpart for the server. You construct the a wrapper using an existing Swish store: ```javascript var wrapper = require('swish-http')(store); ``` You can then register this as an Express middleware at the appropriate location: ```javascript app.use('/json/my-store', wrapper.express()); ``` ## Testing The tests run in the browser. There is an Express-based test server in `test/index.js` which serves a single page (on some available port) and some JavaScript files. The test page/server creates a fresh store for each test, and has no cleanup, so the test server should not run indefinitely. You can start this server using `npm run test-server`. If you append the fragment `#stopOnFirst` to the page, it will halt at the first failed test, instead of continuing testing.