Skip to content

Commit 00b1716

Browse files
committed
Added ability to limit specific socket names
1 parent 955a65a commit 00b1716

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ A simple example of using [Node.js](https://nodejs.org/) to send Growl-style mes
1919

2020
### TODO
2121

22-
- [ ] Add ability to limit specific socket names
22+
- [x] Add ability to limit specific socket names
2323
- [x] Add connect/disconnect state to demo page
2424
- [x] Add field to demo page to submit message
2525
- [x] Add Growl-style example
@@ -60,6 +60,9 @@ If you'd like to have a different [configuration file](https://github.com/lorenw
6060
"api_keys": [
6161
"abc123def",
6262
"tuv456xyz"
63+
],
64+
"sockets": [
65+
"my-socket-name"
6366
]
6467
}
6568
```

config/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"origins": [ "*" ]
88
},
99
"demo_page": true,
10-
"api_keys": []
10+
"api_keys": [],
11+
"sockets": []
1112
}

server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ server.post( '/send/:socket', function( req, res, next ) {
3636

3737
if( config.get( 'api_keys' ).length && ( typeof req.query.api_key === 'undefined' || !config.get( 'api_keys' ).includes( req.query.api_key ) ) ) {
3838
next( new errors.BadRequestError( 'Invalid API key' ) );
39+
} else if( config.get( 'sockets' ).length && !config.get( 'sockets' ).includes( req.params.socket ) ) {
40+
next( new errors.BadRequestError( 'Invalid socket name' ) );
3941
} else {
4042
io.emit( req.params.socket, req.body );
4143
res.send( req.body );

0 commit comments

Comments
 (0)