Move JSCallback to middleware

As a filter, it fails to include headers and status codes that are added to the response in the middleware chain.