Allow requests only for a specific Nodejs route?

Asked

Viewed 276 times

0

I’m trying to create an API gateway, which is going really well. However, when trying to get a microservice to accept ONLY requests through the gateway, I am having trouble. I want any external request blocked, only internal requests can be accepted.

I tried to intercept the requests by request and by replay the routes using the express, but there is no property that tells me that. I tried to use the "Cors" module, but whenever I give a console.log in the "origin" property that comes from it, it comes as null.

Someone could give me a north for this?

1 answer

1


Buddy, you can do this two ways:

1° In your application, by checking the source IP of the requests, you can get it with the command request.connection.remoteAddress. Then just put a validation on your routes.

2° Block all other IP requests from the firewall.

I advise using the second option, I would only use the first if there was no way to implement the firewall lock. This is because the firewall is already developed for this purpose, besides getting more "clean" your application that will be easier to maintain.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.