Skip to content

feature: BaseServer.corsMiddleware should be publicliy modifiable #651

@salihguru

Description

@salihguru

Is your feature request related to a problem? Please describe.

socket.io (here engine.io) uses express's cors library for cors (dependency). I am currently developing a framework and had to write my own cors package in this framework. My framework supports websocket and uses socket.io. So when I try to use my cors package for websocket I do some very unpleasant things.

Describe the solution you'd like

The corsMiddleware function of the BaseServer class must be explicitly changed over the io instance or a middleware must be entered as a cors option.

Describe alternatives you've considered

Alternatively, the following option should be entered:

the current code is right here

    if (this.opts.corsMiddleware) {
       this.corsMiddleware = this.opts.corsMiddleware;
    } else if (this.opts.cors) {
      this.corsMiddleware = require("cors")(this.opts.cors);
    }

and here

    if (this.corsMiddleware) {
      const next = () => {
         this.verify(req, false, callback);
      }
      this.corsMiddleware(this.opts.cors)(req, res, next)
    } else {
      this.verify(req, false, callback);
    }

Although this is not a very good example, I think it is enough to explain my problem. I can create a better PR if you give ideas and support.

Best,
Sami Salih İbrahimbaş

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions