Request forwarding to external URLs and cors

45 views
Skip to first unread message

Krishnaprasad Subbarao

unread,
Jun 17, 2021, 12:02:08 AM6/17/21
to LoopbackJS
Hi, We are working on a nodeJS/loopback application which has few REST APIs to do some CRUD operations. This application also needs to forward requests to external URLs identified at runtime based on a user requests and the data added by CRUD operations. The CRUD operations need authentication and authorization. Where as the requests to be forwarded do not need this support. One of the approach to implement this application I could think off is
i) Implement global interceptors for Authentication, authorization as global interceptors
ii) Controllers, services for CRUD operations on URI /data and apply authentication and authorization on this.
iii) Implement a local interceptor for a controller for particular URI say /forward to invoke middleware provided by node module http-proxy-middleware, to forward the requests to external URLs with headers and body.

Is this a good solution for this problem? What could be a better approach?
How to avoid authentication interceptors getting invoked for requests beling forwarded
Do we need to do any additional to avoid CORS issues as cors is the first middleware called in the sequence

Sharing the sample code as an attachment

loopback-sample-code.ts

Raymond Feng

unread,
Jun 17, 2021, 1:11:35 AM6/17/21
to LoopbackJS
--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/loopbackjs/fa0c4973-24bf-43c9-a7e9-756f5f29ca22n%40googlegroups.com.
<loopback-sample-code.ts>

Reply all
Reply to author
Forward
0 new messages