aldikhan13

MATCHING ROUTE CLIENT & SERVER

Aug 16th, 2020 (edited)
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // TIPS & TRICK
  2. // how to match between client side route and server side route using MERN
  3. // change this code with your route app
  4.  
  5. // add this for react < 16.20 or == 16.20 in package.json
  6. // or add this in your webpack config to webpack dev server, if your build react using manual
  7. "proxy": {
  8.     "/auth/*" : {
  9.       "target": "http://localhost:3001",
  10.       "changeOrigin": true
  11.     }
  12.   }
  13.  
  14. // before add this config install http-proxy-middleware , for react > 16.20 add this from your back-end server
  15. server.use(
  16.   '/auth/*',
  17.   createProxyMiddleware({
  18.     target: 'http://localhost:3001',
  19.     changeOrigin: true,
  20.     xfwd: true
  21.   })
  22. )
Add Comment
Please, Sign In to add comment