mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-06-07 09:48:21 +00:00
27 lines
627 B
JavaScript
27 lines
627 B
JavaScript
|
module.exports = {
|
||
|
*summary() {
|
||
|
return 'The rule to replace websocket message';
|
||
|
},
|
||
|
|
||
|
*beforeSendWsMessageToClient(requestDetail) {
|
||
|
const message = requestDetail.data;
|
||
|
try {
|
||
|
const messageObject = JSON.parse(message);
|
||
|
if (messageObject.type === 'onMessage') {
|
||
|
messageObject.content = 'replaced by beforeSendWsMessageToClient';
|
||
|
return {
|
||
|
data: JSON.stringify(messageObject),
|
||
|
}
|
||
|
}
|
||
|
} catch (err) { /* ignore error */ }
|
||
|
|
||
|
return null;
|
||
|
},
|
||
|
|
||
|
*beforeSendWsMessageToServer() {
|
||
|
return {
|
||
|
data: 'replaced by beforeSendWsMessageToServer',
|
||
|
};
|
||
|
},
|
||
|
};
|