2

I have the CORS feature enabled. I'm finding that if I don't have:

[Route("/cors_endpoint", "GET, OPTIONS")]

on my request dto, then I get a 404.

As I'm using the CorsFeature, and the PreRequestFilter below, I don't understand where this 404 is coming. (I also have authentication attributes in play, but am doing stateless auth with it).

Plugins.Add(new CorsFeature());
PreRequestFilters.Add((req, res) => {
    if (req.Method == "OPTIONS")
    {
         res.StatusCode = 200; //my hack
         res.EndRequest();
    }
});

Any ideas? PS. Still on 3.9.x

Edit: My real questions maybe should be:

[Route("/cors_endpoint", "GET")]

This gives a 404, and doesn't hit the PreRequestFilter at all. Why?

Chris
  • 1,241
  • 1
  • 14
  • 33

1 Answers1

2

The "new API" changes introduced more HTTP verb signatures. Try adding the the service Options method.

public class ReqstarsService : Service
{
    [EnableCors]
    public void Options(Reqstar request) {}
}
kampsj
  • 3,139
  • 5
  • 34
  • 56