apeman-middleware-sse
v1.2.1
Published
apeman middleware package for sse
Downloads
20
Readme
apeman-middleware-sse
apeman middleware package for sse
Installation
$ npm install apeman-middleware-sse --save
Usage
create an middleware instance and attach to server settings like $api
of apeman projects.
Apemanfile.js
/** This is an example Apemanfile to use apeman-middleware-sse */
'use strict'
const co = require('co')
const asleep = require('asleep')
module.exports = {
$pkg: { /* ... */ },
$api: {
/* ... */
$serverMiddlewares: [
require('apeman-middleware-sse')('/sse/bomb', (client) => co(function * () {
let count = 10
while (count >= 0) {
client.send('tick', JSON.stringify(count))
yield asleep(100)
count--
}
client.send('boom!')
}))
]
}
}
Signature
apemanMiddlewareSse(pattern, handler, options) -> function
Create an middleware function
Args
| Name | Type | Default | Description | | --- | ---- | --- | --- | | pattern | string | | URL pattern to apply proxy. | | handler | function | | Handler function for each client | | options | Object | {} | Optional settings |
License
This software is released under the MIT License.