From 698898d405213a32842cef144ba8845ffcc59c5a Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Mon, 5 Jan 2015 12:47:47 -0500 Subject: [PATCH 1/2] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 01d3b2d..67974a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "api-mock", - "version": "0.1.0", + "version": "0.1.1", "description": "A mock server generated from your API Blueprint.", "author": "Evan Cordell ", "main": "lib/api-mock.js", From d86619c1d2e22fd4ca80934ea513536f5341977d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=20P=C3=A4rn=C3=A4nen?= Date: Thu, 5 Mar 2015 11:54:58 +0200 Subject: [PATCH 2/2] Allow for custom Access-Control-Allow-Headers via 'custom-headers' option --- src/api-mock.coffee | 5 ++++- src/cors-support.coffee | 5 ++++- test/unit/api-mock-test.coffee | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/api-mock.coffee b/src/api-mock.coffee index 70369cf..b743f3c 100644 --- a/src/api-mock.coffee +++ b/src/api-mock.coffee @@ -28,7 +28,10 @@ class ApiMock ) if !@configuration.options['cors-disable'] - corsSupport = new CorsSupport @app + corsSupport = new CorsSupport( + @app, + headers: @configuration.options['custom-headers'] + ) run: () -> app = @app diff --git a/src/cors-support.coffee b/src/cors-support.coffee index 91a096e..7f0f339 100644 --- a/src/cors-support.coffee +++ b/src/cors-support.coffee @@ -1,13 +1,16 @@ winston = require 'winston' class CorsSupport - constructor: (app) -> + constructor: (app, configuration) -> options = origin: '*' methods: 'GET, PUT, POST, PATCH, DELETE, TRACE, OPTIONS' headers: 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Referer, Prefer' + if configuration.headers + options.headers = options.headers + ', ' + configuration.headers + app.all '*', (req, res, next) -> unless req.get('Origin') next() diff --git a/test/unit/api-mock-test.coffee b/test/unit/api-mock-test.coffee index 20d0165..17e0542 100644 --- a/test/unit/api-mock-test.coffee +++ b/test/unit/api-mock-test.coffee @@ -73,6 +73,21 @@ describe 'ApiMock class', () -> assert.ok api_mock.configuration.options.port == 3005 assert.notOk CorsSupportStub.called + describe 'with custom Access-Control-Allow-Headers', () -> + + beforeEach ()-> + configuration = + blueprintPath: './test/fixtures/single-get.apib', + options: + port: 3005 + 'custom-headers': 'x-custom-header' + 'cors-disable': false + + it 'should add custom header to configuration', () -> + api_mock = new ApiMock(configuration) + assert.ok api_mock.configuration.options['custom-headers'] == 'x-custom-header' + assert.ok CorsSupportStub.called + describe 'with invalid configuration', () -> beforeEach ()->