I am currently aborting requests the following way (works well in chained event loop futures):
return request.eventLoop.makeFailedFuture(Abort(.badRequest))
My CORS configuration looks like this:
let corsConfiguration = CORSMiddleware.Configuration(allowedOrigin: .all, allowedMethods: [.GET, .POST, .PUT, .OPTIONS, .DELETE, .PATCH], allowedHeaders: [.accept, .authorization, .contentType, .origin, .xRequestedWith])
let corsMiddleware = CORSMiddleware(configuration: corsConfiguration)
app.middleware.use(corsMiddleware)
The problem is that the CORSMiddleware doesn't seem to do anything to the aborted request. How do I fix this so my front end can read the error instead of getting blocked by CORS?
Have a look at the docs for CORSMiddleware - because you want the CORS stuff to trigger before the error middleware you need to register it first. The only way to do that is to set up the whole middleware chain yourself as described