Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jsonrpc-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ JsonRpcAdapter.prototype.createHandler = function () {
urlencodedOptions.extended = true;
}
var jsonOptions = this.remotes.options.json || {strict: false};
var corsOptions = this.remotes.options.cors || {};
var corsOptions = this.remotes.options.cors || {origin: true, credentials: true};
root.use(urlencoded(urlencodedOptions));
root.use(json(jsonOptions));
root.use(cors(corsOptions));
Expand Down
2 changes: 1 addition & 1 deletion lib/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ RestAdapter.prototype.createHandler = function () {
urlencodedOptions.extended = true;
}
var jsonOptions = this.remotes.options.json || {strict: false};
var corsOptions = this.remotes.options.cors || {};
var corsOptions = this.remotes.options.cors || {origin: true, credentials: true};
root.use(urlencoded(urlencodedOptions));
root.use(json(jsonOptions));
root.use(cors(corsOptions));
Expand Down
24 changes: 24 additions & 0 deletions test/rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ describe('strong-remoting-rest', function(){
.expect(413, done);
});

it('should support cors', function(done) {
var method = givenSharedStaticMethod(
function greet(msg, cb) {
cb(null, msg);
},
{
accepts: { arg: 'person', type: 'string', http: {source: 'body'} },
returns: { arg: 'msg', type: 'string' }
}
);

// Build an object that is larger than 1kb
var name = {person: 'ABC'};

request(app)['post'](method.url)
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.set('Origin', 'http://localhost:3000')
.send(name)
.expect('Access-Control-Allow-Origin', 'http://localhost:3000')
.expect('Access-Control-Allow-Credentials', 'true')
.expect(200, done);
});

it('should disable stack trace', function(done) {
objects.options.errorHandler.disableStackTrace = true;
var method = givenSharedStaticMethod(
Expand Down