👋 This is a community project and there is no official support for this package! Feel free to use it, open issues, contribute, and help answering questions.
Middleware for ui5-server to demo WebSocket usage with an simple echo service.
- Requires at least
@ui5/[email protected]
(to supportspecVersion: "3.0"
)
⚠️ UI5 Tooling Compatibility All releases of this tooling extension using the major version3
require UI5 Tooling V3. Any previous releases below major version3
(if available) also support older versions of the UI5 Tooling. But the usage of the latest UI5 Tooling is strongly recommended!
npm install ui5-middleware-websocket --save-dev
- Define the dependency in
$yourapp/package.json
:
"devDependencies": {
// ...
"ui5-middleware-websocket-echo": "*"
// ...
}
- configure it in
$yourapp/ui5.yaml
:
server:
customMiddleware:
- name: ui5-middleware-websocket-echo
afterMiddleware: compression
mountPath: /wsecho
The middleware uses the utility function websocket
which allows to inject a WebSocket middleware function into a UI5 middleware function:
const websocket = require("ui5-middleware-websocket/lib/websocket");
/**
* WebSocket middleware to act as an echo service.
*
* @param {object} parameters Parameters
* @param {@ui5/logger/Logger} parameters.log Logger instance
* @returns {Function} Middleware function to use
*/
module.exports = ({ log }) => {
return websocket(function echo(ws, req /*, next */) {
ws.on("message", function (message) {
log.info(`message: ${message}`);
ws.send(`echo ${message}`);
});
log.info(`Connection established with ${req.url}`);
});
};
This work is dual-licensed under Apache 2.0 and the Derived Beer-ware License. The official license will be Apache 2.0 but finally you can choose between one of them if you use this work.
When you like this stuff, buy @pmuessig a coke when you see him.