Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/psi-4ward/express-websocket
Access express routes through websocket requests
https://github.com/psi-4ward/express-websocket
Last synced: 2 months ago
JSON representation
Access express routes through websocket requests
- Host: GitHub
- URL: https://github.com/psi-4ward/express-websocket
- Owner: psi-4ward
- License: mit
- Created: 2015-01-26T15:24:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-28T11:16:03.000Z (almost 10 years ago)
- Last Synced: 2024-04-11T16:18:29.588Z (9 months ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 7
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-websocket
Access express routes using a [Primus](https://github.com/primus/primus) websocket connection.
### Installation
```
npm install psi-4ward/express-websocket
```### Server
```javascript
// Init express
var app = require('express')();
app.get('/hello', function(req, res) {
// identify / access websocket within routes / middlewares
if(req.isWebsocket) {
console.log('request from spark id', req.spark.id);
}res.send('Hello World!')
});
var httpServer = app.listen(3000);// attach express-websocket
var expressWebsocket = require('express-websocket');
expressWebsocket(app, httpServer, { /* primus options */ });
```In addition to primus options you can pass a `beforeExpress: function(req, res, cb) {...} ` property to hook in right befor the
data goes out to express router.Start your app with `DEBUG=express-websocket node app.js` to enable debug output
### Client
```html
// primus serves its client lib via /primus/primus.jsvar primus = Primus('http://localhost:3000');
var jsonWebRequest = {
type: 'json-web-request',
method: 'GET',
url: '/hello'
};
primus.writeAndWait(jsonWebRequest, console.info.bind(console));
```## License
[MIT](LICENSE)