Skip to content

server template: load middleware via require - #166

Closed
bajtos wants to merge 1 commit into
masterfrom
feature/load-middleware-directly
Closed

bajtos wants to merge 1 commit into
masterfrom
feature/load-middleware-directly

Conversation

@bajtos

@bajtos bajtos commented Nov 3, 2014

Copy link
Copy Markdown
Member

Load middleware directly via require({name}) instead of relying on shorthands provided by loopback.

Requires strongloop/loopback#729

/to @raymondfeng @ritch please review

Load middleware directly via `require({name})` instead of relying
on shorthands provided by loopback.
@bajtos

bajtos commented Nov 3, 2014

Copy link
Copy Markdown
Member Author

Before we get down to implementation details in this change, I'd like to initiate a high-level discussion first.

  • The expressjs way is to install middleware via npm install and load it via require.
  • The current loopback way is to install middleware via npm install and load it via loopback.{name}.

The initial reason for keeping loopback.{name} was to simplify the upgrade path from loopback 1.x (express 3.x) to loopback 2.x (express 4.x).

If that's the only reason why we have loopback.errorHandler and friends, then we should start deprecating them, so that we can remove them in loopback 3.x. This patch is one of the steps along that path.

On the other hand, we may want to make loopback more opinionated and provide users with a pre-selected list of middleware that works well together. In which case it makes sense to keep loopback.{name} shorthands around, this pull request should be rejected and we should document all middleware shorthands in our API docs.

/to @ritch @raymondfeng @altsang @superkhau thoughts?
/cc @crandmck

@raymondfeng

Copy link
Copy Markdown
Member

I would like to have a middleware extension point for LoopBack so that middleware can be registered with LB. The configured middleware will be accessible via loopback.logger or loopback.middleware.logger as the configured logger for LB.

IMO, loopback. gives us more control as we can switch underlying modules across releases.

@bajtos

bajtos commented Nov 3, 2014

Copy link
Copy Markdown
Member Author

@raymondfeng IIUC, you are saying this PR should be rejected because we still want to keep middleware registered on the loopback object. Is that correct?

As for the concept of having "a configured middleware accessible via loopback.logger" - isn't that obsoleted by the new component architecture?

@ritch

ritch commented Nov 3, 2014

Copy link
Copy Markdown
Member

We need to start moving to a less opinionated more node / express compatible server.js. I understand why its enticing to move middleware under our APIs... but I think we really need to move the other direction: compatibility and extensibility with the existing ecosystem of node / express modules.

@bajtos

bajtos commented Nov 3, 2014

Copy link
Copy Markdown
Member Author

@ritch IIUC, you are saying this PR is going in the right direction and it should be landed. Is that correct?

Should we move loopback.urlNotFound middleware to a standalone module?

@ritch

ritch commented Nov 3, 2014

Copy link
Copy Markdown
Member

@ritch IIUC, you are saying this PR is going in the right direction and it should be landed. Is that correct?

Yes. We should remove functionality from loopback that exists in other modules. I think we have two approaches to this:

  1. remove functionality that is available in other well supported modules
  2. split the core into various components...

@ritch

ritch commented Nov 3, 2014

Copy link
Copy Markdown
Member

Should we move loopback.urlNotFound middleware to a standalone module?

Yes. Ideally we would find a module that does this... otherwise a separate module makes sense.

@bajtos

bajtos commented Nov 4, 2014

Copy link
Copy Markdown
Member Author

Should we move loopback.urlNotFound middleware to a standalone module?

Yes. Ideally we would find a module that does this... otherwise a separate module makes sense.

Let's leave that out of scope of this PR.

@bajtos

bajtos commented Nov 4, 2014

Copy link
Copy Markdown
Member Author

@raymondfeng @ritch IMHO the discussion is over, the agreement is to remove loopback.errorHandler and friends at some point in the future. This patch is going in the right direction and should be landed.

Do the changes LGTY?

@bajtos

bajtos commented Nov 4, 2014

Copy link
Copy Markdown
Member Author

@slnode test please

@ritch

ritch commented Nov 4, 2014

Copy link
Copy Markdown
Member

Yep LGTM

@raymondfeng

Copy link
Copy Markdown
Member

I would prefer to hold off the merge until we finalize the middleware/policy management with phases. I'll add more comments when i have access to computers.

@bajtos bajtos assigned raymondfeng and unassigned ritch Nov 4, 2014
@bajtos

bajtos commented Nov 4, 2014

Copy link
Copy Markdown
Member Author

@raymondfeng fair enough. I am reassigning the PR to you, please reassign back when it's time to continue the work.

@bajtos

bajtos commented Nov 20, 2014

Copy link
Copy Markdown
Member Author

Closing in favour of #167

@bajtos bajtos closed this Nov 20, 2014
@bajtos bajtos removed the #review label Nov 20, 2014
@bajtos
bajtos deleted the feature/load-middleware-directly branch December 1, 2014 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants