Skip to content

Commit

Permalink
Merge pull request #90 from smollweide/develop
Browse files Browse the repository at this point in the history
v0.21.0
  • Loading branch information
smollweide authored Jan 23, 2018
2 parents f15319f + d426a41 commit c853864
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
20 changes: 12 additions & 8 deletions doc/readme-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,33 @@ A string that define the header "Content-Type".


#### options.accessControlExposeHeaders
Type: `String`
Type: `String` or `function`
Default value: `X-Total-Count`

A string that define the header "Access-Control-Expose-Headers".
A string that define the header "Access-Control-Expose-Headers". If a function
is used, it will be called with the request object as the only parameter.

#### options.accessControlAllowOrigin
Type: `String`
Type: `String` or `function`
Default value: `*`

A string that define the header "Access-Control-Allow-Origin".
A string that define the header "Access-Control-Allow-Origin". If a function
is used, it will be called with the request object as the only parameter.

#### options.accessControlAllowMethods
Type: `String`
Type: `String` or `function`
Default value: `GET, POST, PUT, OPTIONS, DELETE, PATCH, HEAD`

A string that define the header "Access-Control-Allow-Methods".
A string that define the header "Access-Control-Allow-Methods". If a function
is used, it will be called with the request object as the only parameter.


#### options.accessControlAllowHeaders
Type: `String`
Type: `String` or `function`
Default value: `origin, x-requested-with, content-type`

A string that define the header "Access-Control-Allow-Headers".
A string that define the header "Access-Control-Allow-Headers". If a function
is used, it will be called with the request object as the only parameter.

#### options.middleware
Type: `Object`
Expand Down
24 changes: 20 additions & 4 deletions lib/controller/MockController.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,26 @@ MockController.prototype = extend(MockController.prototype, {
res.setHeader(key, value);
});
res.setHeader('Content-Type', this.options.contentType);
res.setHeader('Access-Control-Expose-Headers', this.options.accessControlExposeHeaders);
res.setHeader('Access-Control-Allow-Origin', this.options.accessControlAllowOrigin);
res.setHeader('Access-Control-Allow-Methods', this.options.accessControlAllowMethods);
res.setHeader('Access-Control-Allow-Headers', this.options.accessControlAllowHeaders);
res.setHeader('Access-Control-Expose-Headers',
typeof this.options.accessControlExposeHeaders === 'function' ?
this.options.accessControlExposeHeaders(res.req) :
this.options.accessControlExposeHeaders
);
res.setHeader('Access-Control-Allow-Origin',
typeof this.options.accessControlAllowOrigin === 'function' ?
this.options.accessControlAllowOrigin(res.req) :
this.options.accessControlAllowOrigin
);
res.setHeader('Access-Control-Allow-Methods',
typeof this.options.accessControlAllowMethods === 'function' ?
this.options.accessControlAllowMethods(res.req) :
this.options.accessControlAllowMethods
);
res.setHeader('Access-Control-Allow-Headers',
typeof this.options.accessControlAllowHeaders === 'function' ?
this.options.accessControlAllowHeaders(res.req) :
this.options.accessControlAllowHeaders
);
},

});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-mock-server",
"version": "0.20.0",
"version": "0.21.0",
"description": "File based Node REST API mock server",
"email": "[email protected]",
"author": "Simon Mollweide <[email protected]>",
Expand Down

0 comments on commit c853864

Please sign in to comment.