Skip to content

Commit

Permalink
Fixes to disable origin control on web requests
Browse files Browse the repository at this point in the history
  • Loading branch information
faazshift committed Feb 27, 2017
1 parent ba60a56 commit 7379dc7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 1 addition & 3 deletions app/src/components/AppMain.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
let React = require('react');
let GraphiQL = require('graphiql');
let fetch = require('isomorphic-fetch');

let MaterialUI = require('material-ui');
let MaterialStyles = require('material-ui/styles');
Expand Down Expand Up @@ -58,11 +57,10 @@ module.exports = class AppMain extends React.Component {
}
} else {
fetchOpts.headers = {'Content-Type': 'application/json'};
window.haha = JSON.stringify(params);
fetchOpts.body = JSON.stringify(params);
}

return fetch(url, fetchOpts).then(response => response.json()).catch((err) => {
return window.fetch(url, fetchOpts).then(response => response.json()).catch((err) => {
return 'Error! Please check the URL and try again!';
});
}
Expand Down
10 changes: 9 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let electron, {app, BrowserWindow} = require('electron');
let {app, session, BrowserWindow} = require('electron');

let path = require('path');
let url = require('url');
Expand All @@ -24,6 +24,14 @@ class GraphiQL_UI {
defaultSize.height = defaultSize.height > display.size.height ? display.size.height : defaultSize.height;

this.config.size = defaultSize;

// Disable pesky origin control for web requests
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
if('Origin' in details.requestHeaders && details.requestHeaders['Origin'] == 'null') {
delete details.requestHeaders['Origin'];
}
callback({cancel: false, requestHeaders: details.requestHeaders});
});
}

createMainWindow() {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"extract-text-webpack-plugin": "^2.0.0",
"graphiql": "^0.9.3",
"graphql": "^0.9.1",
"isomorphic-fetch": "^2.2.1",
"material-ui": "^0.17.0",
"node-sass": "^4.5.0",
"react": "^15.4.2",
Expand Down

0 comments on commit 7379dc7

Please sign in to comment.