-
-
Notifications
You must be signed in to change notification settings - Fork 6
createServer implementation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8ba6454
Draft createServer implementation
getlarge b85b911
add types
getlarge b65f3d4
update gitignore and remove package-lock
getlarge 7e8055a
fix extractConnectionDetails
getlarge 66acea2
extend example
getlarge abf0c59
add unit tests
getlarge 7873a0b
Update dependencies and use protocol decoder from git dev branch
getlarge 6238ace
Follow latest updates from protocol-decoder
getlarge 5abb18c
Use aedes dev branch and validate tests
getlarge 25c0fc4
Update createServer signature and improve conn handling
getlarge cf7fc00
Improve example
getlarge ab4a53e
Add docs
getlarge 830b3aa
minor changes
getlarge b5f21fc
update docs
getlarge 73da018
Change options format
getlarge e1454d6
handle stream error and fix http option
getlarge 8f44b4b
remove error listener afer read
getlarge 01b0742
remove readable listener on error
getlarge 16badbb
update dependencies
getlarge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,146 @@ | ||
| # aedes-server-factory | ||
|
|
||
| Aedes server factory. Supports tcp, tls, http, https, http2, ws, wss and proxy decoders | ||
| Aedes server factory. Supports tcp, http, http2, ws, and proxy decoders | ||
|
|
||
| Work In Progress | ||
| Work In Progress: tls, https, http2, wss | ||
|
|
||
| ## Install | ||
|
|
||
| To install aedes-server-factory : | ||
|
|
||
| ```sh | ||
| npm install aedes-server-factory | ||
| ``` | ||
|
|
||
| # Options | ||
|
|
||
| ## ws | ||
|
|
||
| boolean used to wrap a http | http2 | https server in a websocket server. | ||
|
|
||
| `createServer` will return the http server if not http options is defined. | ||
|
|
||
| ## http2 | ||
|
|
||
| boolean used to create http2 server. | ||
|
|
||
| ## https | ||
|
|
||
| boolean used to create http | http2 secure server. | ||
|
|
||
| ## tls | ||
|
|
||
| boolean used to create tls server. | ||
|
getlarge marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## trustProxy | ||
|
|
||
| boolean to indicates that aedes-server-factory should retrieve information from the Proxy | ||
|
|
||
| ## extractSocketDetails (socket) | ||
|
|
||
| - socket: [`<Duplex | Socket>`] | ||
|
|
||
| Invoked when `options.trustProxy` is `false` | `undefined`. | ||
|
|
||
| [aedes-protocol-decoder] `extractSocketDetails` function is used as default value. | ||
|
|
||
| ```js | ||
| const aedes = require('aedes')() | ||
| const {createServer} = require('aedes-server-factory') | ||
| const yourDecoder = require('./path-to-your-decoder') | ||
|
|
||
| const options = { trustProxy: false } | ||
| options.extractSocketDetails = function(conn, buffer) { | ||
| return yourDecoder(conn, buffer) | ||
| } | ||
|
|
||
| const server = createServer(aedes, options) | ||
| ``` | ||
|
|
||
| ## protocolDecoder (conn, buffer, req) | ||
|
|
||
| - conn: `<Duplex | Socket>` | ||
| - buffer: `<Buffer>` | ||
| - req?: `<IncomingMessage>` | ||
|
|
||
| Invoked when `options.trustProxy` is `true`. | ||
|
|
||
| [aedes-protocol-decoder] `protocolDecoder` function is used as default value. | ||
|
|
||
| ```js | ||
| const aedes = require('aedes')() | ||
| const {createServer} = require('aedes-server-factory') | ||
| const yourDecoder = require('./path-to-your-decoder') | ||
|
|
||
| const options = { trustProxy: true } | ||
| options.protocolDecoder = function(conn, buffer) { | ||
| return yourDecoder(conn, buffer) | ||
| } | ||
|
|
||
| const server = createServer(aedes, options) | ||
| ``` | ||
|
|
||
| ## serverFactory (aedes, options) | ||
|
|
||
| - aedes: [`<Aedes>`](https://github.com/moscajs/aedes/blob/master/docs/Aedes.md) | ||
| - options: `<object>` | ||
|
|
||
| Use to override `createServer` behavior and create your own server instance. | ||
|
|
||
| ```js | ||
| const aedes = require('aedes')() | ||
| const {createServer} = require('aedes-server-factory') | ||
|
|
||
| const options = { trustProxy: false } | ||
| options.serverFactory = function(aedes, options) { | ||
| return net.createServer((conn) => { | ||
| aedes.handle(conn) | ||
| }) | ||
| } | ||
|
|
||
| const server = createServer(aedes, options) | ||
| ``` | ||
|
|
||
| # Examples | ||
|
|
||
| ## TCP server | ||
|
|
||
| ```js | ||
| const aedes = require('aedes')() | ||
| const server = require('aedes-server-factory').createServer(aedes) | ||
|
|
||
| const port = 1883 | ||
|
|
||
| server.listen(port, function () { | ||
| console.log('server started and listening on port ', port) | ||
| }) | ||
| ``` | ||
|
|
||
| ## TCP server behind proxy | ||
|
|
||
| ```js | ||
| const aedes = require('aedes')() | ||
| const server = require('aedes-server-factory').createServer(aedes, { trustProxy: true }) | ||
|
|
||
| const port = 1883 | ||
|
|
||
| server.listen(port, function () { | ||
| console.log('server started and listening on port ', port) | ||
| }) | ||
| ``` | ||
|
|
||
| ## HTTP server for WS | ||
|
|
||
| ```js | ||
| const aedes = require('aedes')() | ||
| const server = require('aedes-server-factory').createServer(aedes, { ws: true }) | ||
| const port = 1883 | ||
|
|
||
| server.listen(port, function () { | ||
| console.log('server started and listening on port ', port) | ||
| }) | ||
| ``` | ||
|
|
||
|
|
||
| [aedes]: https://www.npmjs.com/aedes | ||
| [aedes-protocol-decoder]: https://www.npmjs.com/aedes-protocol-decoder | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.