spa-templates icon indicating copy to clipboard operation
spa-templates copied to clipboard

About http proxy error.

Open yuya-tani opened this issue 3 years ago • 3 comments

Hi.
I got here because I wanted to use react vite on .net6.
I would love to use the template, but I don't know one point, so I'm not sure if it's a good idea to post it here, but please let me know.

I think that it is connected to the API on the .net side with the proxy of vite.config.js, but when I access
"[root]/api/WeatherForecast", the following error is output.

[vite] http proxy error: Error: self signed certificate at TLSSocket.onConnectSecure (_tls_wrap.js:1515:34) at TLSSocket.emit (events.js:400:28) at TLSSocket._finishInit (_tls_wrap.js:937:8) at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:709:12)

vite.config.js has not changed from the initial state,
The key file and pem file are already placed in the "certFilePath" and "keyFilePath" paths in aspnetcore-https.js.

After that, what should I set? I would appreciate it if you could tell me.

Best regard.

yuya-tani avatar Feb 08 '22 08:02 yuya-tani

Set the secure property for the /api route to false:

'/api': {
  target: 'https://localhost:5001/',
  changeOrigin: true,
  secure: false
}

You'll also have to prepend api/ to the route definition on the WeatherforecastController:

[Route("api/[controller]")]

I will update the template accordingly.

johanndev avatar Feb 08 '22 09:02 johanndev

Thank you for your reply.

I fixed it just like your answer and it worked fine! I'm glad that the template will be modified later.

Thank you for your help! Best regard.

yuya-tani avatar Feb 08 '22 09:02 yuya-tani

Is it possible to allow for secure to be true?

wesdevpro avatar Nov 18 '23 23:11 wesdevpro