Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location Proxy with npm serve

If I'm serving a react application with npm install -g serve; serve -s build, is it possible to also have a location proxy?

Ex: any requests to https://example.com/api/* will be redirected to https://example.com:8000/api/*

like image 393
cclloyd Avatar asked May 04 '18 02:05

cclloyd


1 Answers

You can try proxy in package.json

"proxy": {
    "/api": {
      "target": "http://localhost:3001"
    },
    "/assets": {
      "target": "http://localhost:3001"
    }
  },

You may also check environment config options here if above does not solve: https://docs.npmjs.com/misc/config#proxy

like image 108
Rikin Avatar answered Oct 21 '22 07:10

Rikin