Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mount Express middleware #2061

Closed
kawasaki23Ven opened this issue Nov 20, 2018 · 3 comments
Closed

How to mount Express middleware #2061

kawasaki23Ven opened this issue Nov 20, 2018 · 3 comments

Comments

@kawasaki23Ven
Copy link

Hi, I need a Middleware example to all routes of my app.

Example: Verify CORS, Headers,etc.

I would greatly appreciate your help.

@Yaty Yaty added the Examples label Nov 21, 2018
@clayrisser
Copy link
Contributor

I really would like to know how to add middleware. I can't figure it out.

@bajtos
Copy link
Member

bajtos commented Nov 22, 2018

Closing as a duplicate of #1293 (see also #2035 and #1982)

BTW, CORS middleware is automatically enabled by LB4, see https://loopback.io/doc/en/lb4/Server.html#customize-cors

In general, we are trying to move away from Express middleware and use the concept of a Sequence of actions and Dependency Injection to drive the request processing flow.

Could you please be more specific about "Headers" scenario you mentioned in the issue description? What are you trying to achieve? For example, to access a specific request header from your controller method, I would recommend to define a Provider class. It would really help if you could give us a specific example that we could use to drive the docs.

@bajtos bajtos closed this as completed Nov 22, 2018
@bajtos bajtos changed the title Example Create Middleware How to mount Express middleware Nov 22, 2018
@bajtos bajtos added question and removed Examples labels Nov 22, 2018
@clayrisser
Copy link
Contributor

I wrote a component that lets you register express middleware in the sequence.

https://github.com/codejamninja/lb4-middleware

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

No branches or pull requests

4 participants