3

Hi I been trying the proxy solution to avoid the cors problems in myapp but it doesn't seem to work, i restarted my machine so many times and that made no difference. Basically myapp using fetchApi to call another domain (localhost:8080) which is a SpringBoot application endpoint. I added in package.json "proxy": "http://localhost:8080/" but the api still return calls with localhost:3000 and i tried setupProxy.js but i faced same issue....Am i missing anything else ! any help would be appreciated...

const { createProxyMiddleware } = require("http-proxy-middleware");
module.exports = function (app) {
  app.use(
    "/oauth",
    createProxyMiddleware({
      target: "http://localhost:8080",
      changeOrigin: true,
      secure: false,
      logLevel: "debug",
    })
  );
};

3
  • I'm having a similar issue. In setupProxy.js I have something similar to the above and get the following error: [HPM] Error occurred while trying to proxy request /api from localhost:3000 to https://localhost:8080 (DEPTH_ZERO_SELF_SIGNED_CERT) (https://nodejs.org/api/errors.html#errors_common_system_errors) Commented Nov 24, 2020 at 11:07
  • Just wondering how you managed to resolve this? Having the same issue. Thank you Commented Nov 26, 2020 at 4:41
  • @robster I have added some cors codes in my spring boot application to fix this issue. Commented Dec 13, 2020 at 20:25

2 Answers 2

1

I removed the {} on createProxyMiddleware and it started working. Thanks

Sign up to request clarification or add additional context in comments.

1 Comment

there are two {} with two createPM
0

i added in /src folder and named 'setupProxy.js'

i added in /src folder and named 'setupProxy.js'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.