Skip to content

Commit

Permalink
fix: fix origin sent with graphql requests (#541)
Browse files Browse the repository at this point in the history
* fix: fix origin sent with graphql requests

* fix: remove deprecated sinon syntax
  • Loading branch information
bookernath authored and Nabil Cheikh committed Dec 16, 2019
1 parent 41129b0 commit 8f3f02c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/stencil-bundle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Stencil Bundle', () => {
let Bundle;

lab.beforeEach(done => {
sandbox = Sinon.sandbox.create();
sandbox = Sinon.createSandbox();
const themeConfigStub = getThemeConfigStub();
const rawConfig = {
"name": "Cornerstone",
Expand Down
2 changes: 1 addition & 1 deletion bin/stencil-init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('stencil init', () => {
let sandbox;

lab.beforeEach(done => {
sandbox = Sinon.sandbox.create();
sandbox = Sinon.createSandbox();
sandbox.stub(console, 'log');
sandbox.stub(console, 'error');
done();
Expand Down
2 changes: 1 addition & 1 deletion lib/build-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('stencilBuildConfig', () => {
}

lab.beforeEach(done => {
sandbox = sinon.sandbox.create();
sandbox = sinon.createSandbox();
done();
});

Expand Down
2 changes: 1 addition & 1 deletion lib/regions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Stencil Bundle', () => {
let Bundle;

lab.beforeEach(done => {
sandbox = Sinon.sandbox.create();
sandbox = Sinon.createSandbox();
const themeConfigStub = {
configExists: sandbox.stub().returns(true),
getRawConfig: sandbox.stub().returns({}),
Expand Down
2 changes: 1 addition & 1 deletion lib/stencil-push.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('stencil push', () => {

lab.beforeEach(done => {
mockDb.data = {};
sandbox = sinon.sandbox.create();
sandbox = sinon.createSandbox();

sandbox.stub(Wreck, 'get').callsFake(requestStub);
sandbox.stub(Wreck, 'post').callsFake(requestStub);
Expand Down
28 changes: 28 additions & 0 deletions server/plugins/router/router.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const internals = {
favicon: '/favicon.ico',
stencilEditor: '/stencil-editor',
updateParam: '/stencil-editor/update-param',
graphQL: '/graphql',
},
};

Expand Down Expand Up @@ -130,6 +131,33 @@ internals.registerRoutes = function(server, next) {
},
},
},
{
method: ['GET', 'POST'],
path: internals.paths.graphQL,
handler: {
proxy: {
mapUri: function (req, cb) {
return cb(
null,
`${internals.options.storeUrl}${req.path}`,
Object.assign( // Add 'origin' and 'host' headers to request before proxying
req.headers,
{
origin: internals.options.storeUrl,
host: internals.options.storeUrl.replace(/http[s]?:\/\//, ''),
}
)
);
},
passThrough: true,
},
},
config: {
state: {
failAction: 'log',
},
},
},
]);

return next();
Expand Down
17 changes: 17 additions & 0 deletions server/plugins/router/router.module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,21 @@ describe('Router', () => {
done();
});
});

it('should inject host and origin headers for GraphQL requests', done => {
server.inject({
method: 'POST',
url: '/graphql',
headers: { 'authorization': 'abc123' },
}, response => {
expect(response.request.payload.headers).to.include(
{
authorization: 'abc123',
origin: 'https://store-abc123.mybigcommerce.com',
host: 'store-abc123.mybigcommerce.com',
}
);
done();
});
});
});

0 comments on commit 8f3f02c

Please sign in to comment.