Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
React proxy how to prevent from outside world

I have a react js application working on port 3000 and a nodejs working on port 4000. I am using setupProxy as

const createProxyMiddleware = require(`http-proxy-middleware`)
module.exports = function (app) {app.use('/api/*', createProxyMiddleware({ target:http://localhost:4000', changeOrigin: true, }))}

On server, running on port 4000, I am using cors as:

app.use(cors((cors.CorsOptions = { origin: `http://localhost:3000`,})))

The application on localhost:3000 is exposed as https://example.com/ I have an end point on Node server as /api/todos which perfectly accessible from react client.

Outside world can post for example https://example.com/api/todos. How to prevent this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

There was a similar post I answered a few days ago here

How to launch a command on the server from a web page ( nodejs )

With that being said though, and maybe a TLDR you need a way to protect your route. This is where you have two options really.

  1. Use JWT
  2. Use 'sessions' (this would assume you are not connecting / posting from outside the main application so it shares a session between frontend / backend)

From what it sounds like, the application / front-end are not bound together so option 2 may not be an options.

With option one you would create a JWT token from the front end. This token would contain an encoded string that can only be decoded on the server. You send this token with your post or get request and have middleware to decode and verify the token is valid, if not, don't let it post to the route.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!