ASP.NET Core API for access to more than one Angular Apication

Asked

Viewed 21 times

1

I have an API that when launched, it goes up at the following address: http://localhost:49013/api/values. I realized this is parameterized in the file launchSettings.json, that is like:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:49013/",
      "sslPort": 0
    }
  },
  "profiles": 
  {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Cliente.IG.WebAPI": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:49012/"
    }
  }
}

In my API controller, I have this method inside the namespace:

[Produces("application/json")]
[Route("api/IG")]
[ApiController]
public class IGController : Controller
{
    [HttpPost]
    public IGResult Post([FromBody] Filtro filtro)
    {
        var app = new IgApplication();
        return app.getInstrucoes(filtro);
    }
}

"Igapplication" creates an instance of the class where a list is generated that is populated with DAO assigned values.

When I start the angular "A" application via localhost (http://localhost:4200/). Inside my file Environment.prod.ts I have the call:

    export const environment = {
  production: true,
  url: 'http://localhost:49013/'
};

It goes through this controller and follows the flow and does what has to be done.

But here’s the thing! I have the application "B", which accesses the same API but has different functionalities, so within the same controller I created a new class and a method:

[Produces("application/json")]
[Route("api/Item")]
public class APIIgItemController : Controller
{
    [HttpGet]
    public ItensResult Post([FromBody] Itens ValorItem)
    {
        var app = new CRUDApplication();
        return app.GetItens();
    }
}

How do I stop when starting the "B" application, it goes through this "Itensresult" method instead of "Igresult", both of which are executed by localhost:4200? Or is this what I define in the angular application? I saw that it is possible to configure more than one "applicationUrl" within json. I should consider this setting?

Thanks for all your help!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.