Fix the graph API failures

Summary:
Currenty in the prod version of Flipper the endpoints of media upload and flipper trace fail with status code 400. Reason being different origin and refferer as compared to the dev version. This diff matches the origin and the refferer with the dev one.

I referenced Anton's diff D20278701.

Reviewed By: nikoant

Differential Revision: D20454562

fbshipit-source-id: 20f80a731878fb491d08a208d64fc9260e442fa3
This commit is contained in:
Pritesh Nandgaonkar
2020-03-16 05:20:11 -07:00
committed by Facebook GitHub Bot
parent 148f90de7f
commit d75be90522

View File

@@ -16,6 +16,7 @@ import {
ipcMain,
Notification,
globalShortcut,
session,
} from 'electron';
import path from 'path';
import url from 'url';
@@ -191,6 +192,7 @@ app.on('ready', () => {
}
appReady = true;
app.commandLine.appendSwitch('scroll-bounce');
configureSession();
tryCreateWindow();
// if in development install the react devtools extension
if (process.env.NODE_ENV === 'development') {
@@ -205,6 +207,21 @@ app.on('ready', () => {
});
});
function configureSession() {
session.defaultSession.webRequest.onBeforeSendHeaders(
{
urls: ['*://*/*'],
},
(details, callback) => {
// setting Origin to always be 'localhost' to avoid issues when dev version and release version behaves differently.
details.requestHeaders.origin = 'https://localhost:3000';
details.requestHeaders.referer = 'https://localhost:3000/index.dev.html';
callback({cancel: false, requestHeaders: details.requestHeaders});
},
);
}
app.on('will-quit', () => {
globalShortcut.unregisterAll();
});