CORS support
xjamundx opened this issue · comments
I was going to ask for CORS support in the createServer
method, but then I did this instead using createMiddleware
:
import { createMiddleware } from '@mswjs/http-middleware';
import express from 'express';
import cors from 'cors';
import { handlers } from './handlers';
const app = express();
app.use(cors());
app.use(express.json());
app.use(createMiddleware(...handlers));
app.listen(8082);
Opening purely so if someone searches for CORS they can see how to add it.
Or maybe you can put it in the docs.
Hi, @xjamundx. Thanks for leaving this here for posterity!
Yes, in the case of more specific behaviors, such as adding a CORS middleware, it's expected to use this library via the createMiddleware()
function, attaching it to your own server. I believe that to be implied knowledge but I may add a mention to the docs regarding this.