unit
unit copied to clipboard
Add WebSocket support for `ws` moudle in `unit-http`
While trying to fix the error #1219 & browsing the source code of the unit-http module on https://www.npmjs.com/package/unit-http?activeTab=code i stumbled across the file "loader.js".
It seems like only the "websocket" module is support and not also "ws" as npm package/overriding:
// can only be ran as part of a --require param on the node process
if (module.parent && module.parent.id === "internal/preload") {
const { Module } = require("module")
if (!Module.prototype.require.__unit_loader) {
const http = require("./http")
const websocket = require("./websocket")
const original = Module.prototype.require;
Module.prototype.require = function (id) {
switch(id) {
case "http":
case "node:http":
case "unit-http":
return http
case "websocket":
case "node:websocket":
case "unit-http/websocket":
return websocket
}
return original.apply(this, arguments);
}
Module.prototype.require.__unit_loader = true;
}
}
Would it be possible to ad a "ws" case for WebSockets? (Which is the far popular used WebSocket module)
|
Where can i find the source code/repo of the unit-http module?
Side note: there is no "node:websocket" module.