Reputation: 9214
I have a .NET Core API hosted in Azure. When running my Angular UI locally (version 8) I want to point API requests to my app service running in Azure. To do this, I set up my Angular proxy.conf.json file like so:
{
"/api": {
"target": "http://my-app.azurewebsites.net",
"secure": false,
"logLevel": "debug",
"changeOrigin": "true"
},
When I run the UI locally and attempt to log in I'm seeing these 3 requests Chrome's network debugger:
[General]
Request URL: http://localhost:4200/api/account/login
Request Method: GET
Status Code: 301 Moved Permanently
[Response Headers]
location: https://my-app.azurewebsites.net/api/account/login
server: Microsoft-IIS/10.0
---
[General]
Request URL: https://my-app.azurewebsites.net/api/account/login
Request Method: OPTIONS
Status Code: 204 No Content
[Response Headers]
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: http://localhost:4200
---
[General]
Request URL: https://my-app.azurewebsites.net/api/account/login
Request Method: GET
Status Code: 404 Not Found
What's particularly odd is that my login request (as called from my UI) is a POST, not a GET.
I've configured Angular's dev-server proxy in many projects and never seen this before. Feels like I'm missing something obvious..
Upvotes: 0
Views: 435
Reputation: 9214
I forgot that I had recently updated my Azure app to by "HTTPS Only"! Since my proxy was configured to send traffic to the "http", the Azure server was returning a 301, as it should.
Once I changed my proxy config file to account for that everything worked as expected:
{
"/api": {
"target": "https://my-app.azurewebsites.net", <-- https now
"secure": false,
"logLevel": "debug",
"changeOrigin": "true"
},
Knowing this, the details for the 3 HTTP requests that I saw in Chrome makes more sense - I can see Azure is returning a 301 redirecting me to the same route, but with "https" this time.
Upvotes: 3