diff --git a/public/main.js b/public/main.js index dff3ce8..358fad6 100644 --- a/public/main.js +++ b/public/main.js @@ -1,5 +1,7 @@ const { app, BrowserWindow } = require('electron'); const isDev = require('electron-is-dev'); +const path = require('path'); +const os = require('os'); if (isDev) { console.log('Running in development'); @@ -15,11 +17,18 @@ function createWindow() { height: 600, webPreferences: { nodeIntegration: true, + webSecurity: false, }, }); mainWindow.loadURL(isDev ? 'http://localhost:8080' : `file://${__dirname}/../dist/index.html`); + + if (isDev) { + BrowserWindow.addDevToolsExtension( + path.join(os.homedir(), './Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/3.6.0_0'), + ); + } mainWindow.on('closed', () => { mainWindow = null; }); diff --git a/src/main/components/HeaderBar.jsx b/src/main/components/HeaderBar.jsx new file mode 100644 index 0000000..48889ee --- /dev/null +++ b/src/main/components/HeaderBar.jsx @@ -0,0 +1,29 @@ +import React from 'react'; + +const HeaderBar = (props) => { + const { + header, authType, handleChange, + } = props; + + console.log(authType); + return ( +
+

Headers

+
+ + + +
+
+ ); + +}; + +export default HeaderBar; diff --git a/src/main/components/RequestBar.jsx b/src/main/components/RequestBar.jsx index d6f77fe..791a21c 100644 --- a/src/main/components/RequestBar.jsx +++ b/src/main/components/RequestBar.jsx @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import HeaderBar from './HeaderBar.jsx'; const RequestBar = (props) => { const { @@ -9,11 +10,30 @@ const RequestBar = (props) => { const [selected, setSelected] = useState(method); const [uri, setUri] = useState(''); + // header info + const [headerType, setHeaderType] = useState('Authorization'); + const [authType, setType] = useState('Bearer Token'); + const [headerKey, setHeaderKey] = useState(''); const handleChange = (e) => { const { name, value } = e.target; if (name === 'method') setSelected(value); else if (name === 'uri') setUri(value); + + // header info + if (name === 'Authentication') setHeaderType(value); + if (name === 'headerKey') setHeaderKey(`Bearer ${value}`); + + }; + + const runTest = (link, sendingObj, testsClone, i) => { + const test = testsClone; + fetch(link, sendingObj) + .then((response) => { + test[i].status = response.status; + if (i === test.length - 1) setTests(test); + }) + .catch(error => console.log(error)); }; function sendFetch(e) { @@ -21,6 +41,7 @@ const RequestBar = (props) => { if (SourceOrDest === 'source') { const sendingObj = { method: selected, mode: 'cors' }; + if (headerType !== 'NONE') sendingObj.headers = { [headerType]: headerKey }; fetch(uri, sendingObj) .then(res => res.json()) @@ -28,17 +49,11 @@ const RequestBar = (props) => { } else if (SourceOrDest === 'dest') { const testsClone = [...tests]; const sendingObj = { method: selected, mode: 'cors' }; - let counter = 0; + if (headerType !== 'NONE') sendingObj.headers = { [headerType]: headerKey }; + for (let i = 0; i < testsClone.length; i += 1) { sendingObj.body = JSON.stringify(testsClone[i].payload); - - fetch(uri, sendingObj) - .then((response) => { - counter += 1; - testsClone[i].status = response.status; - if (counter === testsClone.length) setTests(testsClone); - }) - .catch(error => console.log(error)); + runTest(uri, sendingObj, testsClone, i); } } } @@ -65,6 +80,7 @@ const RequestBar = (props) => { + ); }; diff --git a/src/main/components/ResponseComponent.jsx b/src/main/components/ResponseComponent.jsx index 2942e61..f3ef263 100644 --- a/src/main/components/ResponseComponent.jsx +++ b/src/main/components/ResponseComponent.jsx @@ -10,7 +10,7 @@ const ResponseComponent = (props) => { return (
-

{`${checkmark} ' - ' ${status}`}

+

{`${checkmark} - ${status}`}