nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.37k stars 323 forks source link

Add WebSocket support for `ws` moudle in `unit-http` #1220

Open mStirner opened 5 months ago

mStirner commented 5 months ago

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)

image | image

Where can i find the source code/repo of the unit-http module?

Side note: there is no "node:websocket" module.