expressflaskserverclient

Client communicate with the server using localhost:PORT


I have a small question: Is it possible for the client to communicate with the server using localhost?

I'm trying to do that so to prevent the users from directly accessing the service and use it for free.. So, I've wanted to make the client communicate with the localhost (hosted in server).

Additionally, I'm using JavaScript (NodeJS - ExpressJS - NextJS) and Python (Flask)

Main question: Are there any solutions to this? If not, are there alternative ways to prevent users from accessing the service?

I deployed Express.js and Flask, with Express.js handling the API and Flask managing internal tasks like translation. I set up the client to communicate with localhost (where Flask is running) for these internal services. I expected it to work, but it only worked on my local machine.


Solution

  • Any client from a different machine does not have any access to your localhost, since localhost is a host, in which the client and server are running on the same computer.

    Even so, for restricting the service access, you can implement authentication, authorization, and reverse proxy mechanisms. For instance, JWT, OAuth, NGINX reverse proxy, and API key authentication mechanisms.