Skip to content

Commit a6ef7f7

Browse files
committed
0.4.7 fixed ws receiving a bunch of messages
1 parent 2ce8d6e commit a6ef7f7

File tree

16 files changed

+683
-801
lines changed

16 files changed

+683
-801
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.4.7
2+
- API clean up, removed `.open()`, `.close()` methods for HTTP and WS hosts
3+
- Added `.config()` method for WS host
4+
- Improved logger, added configurable stream
5+
- Renamed configuration names for HTTP and WS hosts (some changes may still be made here)
6+
- Fixed WebSocket parsing when receiving a bunch of frames
7+
- Other small bugfixes
8+
19
## 0.4.6
210
- Fixed POST requests behavior
311
- Made that `.host()` method will create or return an existing host or the main host
@@ -201,4 +209,4 @@
201209
- Modified `.start()` method to be more asynchronous
202210

203211
## 0.0.1
204-
- First public release
212+
- First public release

DOCUMENTATION.md

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
1111
> ##### [Virtual Hosting](#server-host)
1212
13-
> ##### [Host Management](#server-host-management)
13+
> ##### [Host Configuration](#server-host-config)
1414
1515
> ##### [Templating](#server-templating)
1616
1717
### [Routing](#host-routing)
18-
>##### [General Routing](#host-route)
19-
2018
>##### [All Requests](#host-all)
2119
2220
>##### [DELETE Requests](#host-del)
@@ -27,6 +25,8 @@
2725
2826
>##### [PUT Requests](#host-put)
2927
28+
>##### [General Routing](#host-route)
29+
3030
>##### [Error Routes](#host-error)
3131
3232
>##### [Examples for routes](#example-routes)
@@ -162,7 +162,7 @@ port: number
162162

163163
callback: function()
164164

165-
Start listening for requests on the provided port. If the server was started before, simpleS will get sessions from the `.sessions` file if they exist or they have a valid structure. If the server is already started, then simpleS will restart the server and will listen on the new provided port. Can have an optional callback. All connection in simpleS are kept alive and the restart can take few seconds, for closing alive http and ws connections. While restarting, no new connection will be accepted but existing connections will be still served. This method is called automatically when a new simpleS instance is created, it is not needed to call it explicitly on server creation. The purpose of this method is to provide a way to switch port or to start a stopped simpleS instance.
165+
Start listening for requests on the provided port. If the server is already started then simpleS will restart the server and will listen on the new provided port. Can have an optional callback. All connection in simpleS are kept alive and the restart can take few seconds for closing alive http and ws connections. While restarting, no new connection will be accepted but existing connections will be still served. This method is called automatically when a new simpleS instance is created, it is not needed to call it explicitly on server creation. The purpose of this method is to provide a way to switch port.
166166

167167
```javascript
168168
server.start(80, function () {
@@ -176,7 +176,7 @@ server.start(80, function () {
176176

177177
callback: function()
178178

179-
Stop the server. The existing sessions are saved to the `.sessions` file for further access. Can have an optional callback. All connection in simpleS are kept alive and the closing can take few seconds, for closing alive http and ws connections. While closing, no new connection will be accepted but existing connections will be still served. The purpose of this method is to provide a way for closing the server and save the existing session for future use.
179+
Stop the server. Can have an optional callback. All connection in simpleS are kept alive and the closing can take few seconds for closing alive http and ws connections. While closing, no new connection will be accepted but existing connections will be still served.
180180

181181
```javascript
182182
server.stop(function () {
@@ -186,54 +186,48 @@ server.stop(function () {
186186

187187
### <a name="server-host"/> Virtual Hosting
188188

189-
`.host(name)`
189+
`.host(name[, config])`
190190

191191
name: string
192192

193-
simpleS can serve multiple domains on the same server and port, using `.host()` method it is simple to specify which host should use which routes. By default, simpleS has the main host which will route all existent routes of the simpleS instance, this is vital for one host on server or when it is needed a general behavior for incoming requests. Routing methods explained below are applicable on simpleS instance, for the main host, and on this method to define different hosts.
193+
config: object
194+
195+
simpleS can serve multiple domains on the same server and port, using `.host()` method it is simple to specify which host should use which routes. By default, simpleS has the main host which will route all existent routes of the simpleS instance, this is vital for one host on server or when it is needed a general behavior for incoming requests. This method will create and configure a new host or will return an existing host with a changed configuration.
194196

195197
```javascript
196198
var host = server.host('example.com');
197199
```
198200

199-
#### <a name="server-host-management"/> Host Management
200-
201-
`.open()`
202-
203-
Make the host active, this method is called automatically when a new host is created, it is not needed to call it explicitly on host creation.
204-
205-
`.close()`
206-
207-
Closes all the child WebSocket hosts and make the host inactive.
208-
209-
`.destroy()`
210-
211-
Close the host and removes it from the server. Can not destroy the main host, for the main host all routes will be cleaned as it would be a new created host.
201+
#### <a name="server-host-config"/> Host Configuration
212202

213203
`.config(config)`
214204

215205
config: object
216206

217207
Change the configuration of the host. Possible attributes:
218208

219-
`compression: boolean // true` - switch the compression of the response content, default is true
209+
`useCompression: boolean // true` - Switch the compression of the response content, default is true
220210

221-
`limit: number // 1048576` - set the limit of the request body in bytes, default is 1MB.
211+
`requestLimit: number // 1048576` - Set the limit of the request body in bytes, default is 1MB.
222212

223-
`origins: array of strings // []` - set the origins accepted by the host. By default, the server will accept requests only from the current host. To accept requests from any origin use `'*'`, if this parameter is used as the first parameter then all next origins are rejected. `'null'` is used for local file system origin. These limitations will work for `HTTP` `GET` and `POST` request and even for `WebSocket` requests. The current host should not be added in the list, it is accepted anyway.
213+
`acceptedOrigins: array of strings // []` - Set the origins accepted by the host. By default, the server will accept requests only from the current host. To accept requests from any origin use `'*'`, if this parameter is used as the first parameter then all next origins are rejected. `'null'` is used for local file system origin. These limitations will work for `HTTP` `GET` and `POST` request and even for `WebSocket` requests. The current host should not be added in the list, it is accepted anyway.
224214
```javascript
225215
['null', 'localhost', 'example.com'] // Will accept requests only from these 3 hosts
226216

227217
['*', 'example.com'] // Will accept requests from all hosts except 'example.com'
228218
```
229219

230-
`referers: array of strings // []` - set the referers that can use the static resources of the host. By default, the server will response to all referers. To accept all referers except some specific the first parameter should be `*`. The current host should not be added in the list, it is served anyway. The server will respond with error 404 to unacceptable referers.
220+
`acceptedReferers: array of strings // []` - Set the referers that can use the static resources of the host. By default, the server will response to all referers. To accept all referers except some specific the first parameter should be `*`. The current host should not be added in the list, it is served anyway. The server will respond with error 404 to unacceptable referers.
231221
```javascript
232222
['*', 'example.com'] // will respond to all referers except 'example.com'
233223

234224
['example.com', 'test.com'] // Will respond only to these 2 referers
235225
```
236226

227+
`sessionTimeout: number // 3600` - Set the time to live of a session in seconds, default is 1 hour.
228+
229+
`sessionPassword: string // ""` - Set the password for encrypting the session data on the client. Should be set as a long random string to improve security. The password should be kept the same after server restart to be sure that all the client session data is available. Default is an empty string.
230+
237231
### <a name="server-templating"/> Templating
238232

239233
`.engine(engine)`
@@ -291,17 +285,6 @@ All the methods described below are applicable on each host independently (see [
291285
*/
292286
```
293287

294-
### <a name="host-route"/> General routing
295-
`.route(type, route, result)`
296-
297-
type: 'all', 'del', 'get', 'put' or 'post'
298-
299-
route: array[strings] or string
300-
301-
result: function(connection) or string
302-
303-
Can add listeners for all types of routes. The methods described below are just shortcuts to this method. For better legibility use shortcuts.
304-
305288
### <a name="host-all"/> All Requests
306289

307290
`.all(route, result)`
@@ -352,6 +335,17 @@ result: function(connection) or string
352335

353336
Listen for `PUT` requests and uses a callback function with connection as parameter or a string for rendering (see `Connection.render()`).
354337

338+
### <a name="host-route"/> General routing
339+
`.route(type, route, result)`
340+
341+
type: 'all', 'del', 'get', 'put' or 'post'
342+
343+
route: array[strings] or string
344+
345+
result: function(connection) or string
346+
347+
Can add listeners for all types of routes. The methods described below are just shortcuts to this method. For better legibility use shortcuts.
348+
355349
### <a name="host-error"/> Error Routes
356350

357351
`.error(code, result)`
@@ -425,11 +419,13 @@ serve.leave('all', [
425419

426420
### <a name="host-log"/> Logging
427421

428-
`.log(callback)`
422+
`.log([stream, ]callback)`
423+
424+
stream: object(writable stream instance) or string
429425

430426
callback: function(connection)
431427

432-
Allows to log data about the established connections, will write data to the `process.stdout` using `console.log` interface. The callback should return data which will be shown in the console. The callback function is triggered on HTTP and WS requests.
428+
Allows to log data about the established connections, will write data to the `process.stdout` stream or a defined writable stream, if the `stream` parameter is a string then the logger will write to file with the path described in the string. The `callback` parameter should return data which will be shown in the console. This function is triggered on new HTTP and WS requests.
433429

434430
```javascript
435431
server.log(function (connection) {
@@ -443,7 +439,7 @@ The parameter provided in callbacks for routing requests is an object that conta
443439

444440
```javascript
445441
{
446-
body: '',
442+
body: [],
447443
cookies: {
448444
user: 'me',
449445
pass: 'password'
@@ -491,7 +487,7 @@ The parameter provided in callbacks for routing requests is an object that conta
491487

492488
#### <a name="http-connection-body"/> .body
493489

494-
The content of the body of the request, for `GET` requests it is empty, for `POST` request it will contain plain data, parsed data is contained in `connection.query` or `connection.files`.
490+
The content of the body of the request, for `GET` requests it is empty, for `POST` request it will contain plain data, parsed data is contained in `connection.query` or `connection.files`, this data is represented by a buffer.
495491

496492
#### <a name="http-connection-cookies"/> .cookies
497493

@@ -630,7 +626,7 @@ data: any value
630626

631627
replacer: array[numbers or strings] or function(key, value)
632628

633-
space: number of string
629+
space: number or string
634630

635631
Writes preformatted data to the response stream and ends the response, implements the functionality of `JSON.stringify()` for arrays, booleans, numbers and objects, buffers and strings are sent as they are. Should not be used with `.write()` or `.end()` methods, but `.write()` method can be used before. Should be used only once.
636632

@@ -672,15 +668,15 @@ The WebSocket host is linked to the current or the main HTTP host (see Virtual H
672668

673669
### <a name="ws-host"/> WebSocket Host
674670

675-
`.ws(location, [config, ]callback)`
671+
`.ws(location[, config], listener)`
676672

677673
location: string
678674

679675
config: object
680676

681-
callback: function(connection)
677+
listener: function(connection)
682678

683-
Create WebSocket host and listen for WebSocket connections. For security reasons only requests from the current host or local file system origins are accepted, to accept requests from another locations the `origins` parameter from the configuration object of the host must bedefined. Also, for additional security or logic separation, protocols should be provided in the `config` parameter, they should match on the server and on the client, the length of the message can be limited too by the value of `limit` parameter, default is 1MiB, the value is defined in bytes. The connection can be used in raw and advanced mode. The advanced mode allows an event based communication over the WebSocket connection, while the raw mode represents a low level communication, default is advanced mode. The callback function comes with the connection as parameter.
679+
Create a WebSocket host and listen for WebSocket connections. For security reasons only requests from the current host or local file system origins are accepted, to accept requests from another locations the `origins` parameter from the configuration object of the host must be defined. Also, for additional security or logic separation, protocols should be provided in the `config` parameter, they should match on the server and on the client, the length of the message can be limited too by the value of `limit` parameter, default is 1MiB, the value is defined in bytes. The connection can be used in raw and advanced mode. The advanced mode allows an event based communication over the WebSocket connection, while the raw mode represents a low level communication, default is advanced mode. The callback function comes with the connection as parameter.
684680

685681
```javascript
686682
var echo = server.ws('/', {
@@ -692,13 +688,13 @@ var echo = server.ws('/', {
692688
});
693689
```
694690

695-
#### <a name="ws-host-open"/> .open([config, callback])
691+
#### <a name="ws-host-config"/> .config([config, callback])
696692

697693
config: object
698694

699695
callback: function(connection)
700696

701-
Restarts the WebSocket host with new configuration and callback. The missing configuration parameters will not be changed. This method is called automatically when a new WebSocket host is created, it is not needed to call it explicitly on WebSocket host creation.
697+
Restarts the WebSocket host with new configuration and callback. The missing configuration parameters will not be changed.
702698

703699
```javascript
704700
echo.open({
@@ -708,14 +704,9 @@ echo.open({
708704
// Application logic
709705
});
710706
```
711-
712-
#### <a name="ws-host-close"/> .close()
713-
714-
Stops the WebSocket host. Will close all existing connections and will not receive new connections.
715-
716707
#### <a name="ws-host-destroy"/> .destroy()
717708

718-
Will stop the current WebSocket host and will remove it from the WebSocket hosts list.
709+
Close all existing connections and remove the host from the WebSocket hosts list.
719710

720711
#### <a name="ws-host-broadcast"/> .broadcast([event, ]data[, filter])
721712

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# simpleS 0.4.6
1+
<img src="https://raw.github.com/micnic/simpleS/master/logo.png"/>
2+
# 0.4.7
23

34
simpleS is a simple HTTP(S) server for Node.JS that has some special features:
45

0 commit comments

Comments
 (0)