From d75be90522189787d1f8b9e6242007ad168a3067 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Mon, 16 Mar 2020 05:20:11 -0700 Subject: [PATCH] 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 --- desktop/static/main.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/desktop/static/main.ts b/desktop/static/main.ts index 13b5977ad..841828cab 100644 --- a/desktop/static/main.ts +++ b/desktop/static/main.ts @@ -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(); });