fixes bug with CORS headers

This commit is contained in:
James
2020-08-19 16:29:35 -04:00
parent aaee4d16d1
commit b5690cf721
2 changed files with 5 additions and 5 deletions

View File

@@ -5,9 +5,9 @@ const testError = new APIError('test error', 503);
const mockResponse = () => {
const res = {};
res.status = jest.fn()
jest.spyOn(res, 'status').mockImplementation()
.mockReturnValue(res);
res.send = jest.fn()
jest.spyOn(res, 'send').mockImplementation()
.mockReturnValue(res);
return res;
};
@@ -33,7 +33,7 @@ describe('errorHandler', () => {
});
it('should send the response with the error', async () => {
const handler = errorHandler({ debug: true, hooks: {}});
const handler = errorHandler({ debug: true, hooks: {} });
await handler(testError, req, res);
expect(res.send)
.toHaveBeenCalledWith(
@@ -51,7 +51,7 @@ describe('errorHandler', () => {
});
it('should not include stack trace when config debug is not set', async () => {
const handler = errorHandler({hooks: {}});
const handler = errorHandler({ hooks: {} });
await handler(testError, req, res);
expect(res.send)
.toHaveBeenCalledWith(

View File

@@ -29,7 +29,7 @@ const middleware = (payload) => [
(req, res, next) => {
if (payload.config.cors) {
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin X-Requested-With, Content-Type, Accept, Authorization');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
if (payload.config.cors === '*') {
res.setHeader('Access-Control-Allow-Origin', '*');