Typescript client CORS error

I am running into an interesting anomaly with one particular call from typescript. All other’s work fine.

Error:
Access to fetch at ‘https://localhost:8443/json/reply/Object’ from origin ‘http://localhost:4205’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

Config:

Plugins.Add(new CorsFeature(allowedOrigins: "http://localhost:4205",
            allowedMethods: "GET, POST, PUT, DELETE, OPTIONS,PATCH",
        allowedHeaders: "Content-Type,enctype,filename,Authorization",
                                            allowCredentials: true));

DTO:

[Route("/shipping","POST")]
public class shippingCostSchedule : IReturn<shippingCostSchedule>
{

    public decimal to_price_1 { get; set; }
    public decimal to_price_2 { get; set; }
    public decimal shipping_cost_1 { get; set; }
    public decimal shipping_cost_2 { get; set; }
    public decimal shipping_cost_3 { get; set; }

    

}

TS Code:

changeShippingCost()
{

  var client = new JsonServiceClient(this.baseUrl);
  client.bearerToken = this.bearerToken;
  try {   
    const response =  client.post(this.shippingCost); 
    response.then(data=> ...

https://localhost:8443/json/reply/Object

Looks like an invalid url, make sure the Request DTO you’re sending is definitely one of the generated Request DTOs and not an anonymous object.

I don’t know why the client is sending it to that url. The DTO’s for typescript were generated by

typescript-ref https://localhost:8443 dtos.ts

And looks like this:

// @Route("/shipping2", "GET")

    export class getshippingCostSchedule implements IReturn<shippingCostSchedule>
{
    public constructor(init?:Partial<getshippingCostSchedule>) { (<any>Object).assign(this, init); }
    public createResponse() { return new shippingCostSchedule(); }
    public getTypeName() { return 'getshippingCostSchedule'; }
}

the post body looks good

I’m saying make sure the DTO you pass into the JsonServiceClient APIs is one of the generated DTOs, sending the getshippingCostSchedule Request DTO would not generate an /Object URL.

console.log() the DTO before you send it to make sure you’re actually sending an actual Request DTO and not an anonymous object.

Hmmm ok yes, even though I am new’ing that object up from the DTO, it looks like angular bindings are mangling it somehow (very strange… but obviously not SS issue.) Once again, many thanks