Skip to content

Express autodetection doesn't work properly #322

@aadamowski

Description

@aadamowski

It seems that the approach for Express autodetection is by patching the connect's HTTPServer use() function in memory:

b854bc5#index.js

For some reason this doesn't work in my application, which uses everyauth indirectly through mongoose-auth (don't know if that's relevant since mongoose-auth clearly delegates middleware() and helpExpress() function calls without interfering).

My app hooks up everyauth this way:

config.app.use(mongooseAuth.middleware());

After adding some debug statements to everyauth/index.js, I've determined that everyauth's middleware() function gets run, but the replaced connect use() implementation isn't. Probably because, in my case, use() call happens (begins) before everyauth middleware() patches it.

Besides, the fact that everyauth middleware() can potentially be called by connect's methods and then itself reaches to connect's method (and overrides its implementation - regardless of whether their code is compatible or not!) creates a cyclic dependency between everyauth and connect.

In general, this causes real problems and is an example of:

bad code smells:

  • inappropriate intimacy (a class that has dependencies on implementation details of another class)
  • cyclic dependency

violations of at least 2 [SOLID](http://en.wikipedia.org/wiki/Solid_(object-oriented_design\)) principles:

All that in the name of saving the programmer from making a single function call (helpExpress()), and with a price that he cannot decide anymore about the moment when it is performed.

I vote for the revert of commit b854bc5 and bringing back the helpExpress() function, which has worked just fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions