Navigation Menu

Skip to content

Commit

Permalink
working dev/prod scripts for proxy. cors should be solved for build a…
Browse files Browse the repository at this point in the history
…nd dev
  • Loading branch information
wrobinson91 committed Aug 3, 2019
1 parent effba10 commit 88eb3db
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.development
@@ -0,0 +1 @@
IS_DEV=1
1 change: 1 addition & 0 deletions .env.production
@@ -0,0 +1 @@
IS_DEV=0
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -3,5 +3,4 @@ build/
dist/
package-lock.json
.cache/
.env
.vscode/
4 changes: 3 additions & 1 deletion client/App.jsx
Expand Up @@ -8,7 +8,9 @@ import Header from './Components/Header';
import QueriesContainer from './Containers/QueriesContainer';
import { StateProvider, useStateValue } from './Context';
// using a proxy to get around CORS. WE PROBABLY NEED A SERVER NOW.
const proxy = 'https://cors-anywhere.herokuapp.com/';
const proxy = process.env.IS_DEV ? 'https://cors-anywhere.herokuapp.com/' : '';
console.log('proxy is: ', proxy)
// const proxy = 'https://cors-anywhere.herokuapp.com/';


const App = () => {
Expand Down
7 changes: 5 additions & 2 deletions client/Components/QueryInput.jsx
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import gql from 'graphql-tag';
import { Controlled as CodeMirror } from 'react-codemirror2';
// import NodeFetch from 'node-fetch';
import { useStateValue } from '../Context';
import EndpointField from './EndpointField';
import fetchErrorCheck from '../utils/fetchErrorCheck';
Expand All @@ -11,7 +12,9 @@ import '../StyleSheets/external/CodeMirror.css';


// using a proxy to get around CORS. WE PROBABLY NEED A SERVER NOW.
const proxy = 'https://cors-anywhere.herokuapp.com/';
// const proxy = 'https://cors-anywhere.herokuapp.com/';
console.log('env is dev: ', process.env.IS_DEV);
const proxy = process.env.IS_DEV ? 'https://cors-anywhere.herokuapp.com/' : '';

// wrote example query so it can be used as a placeholder in textarea
const exampleQuery = `# Example query:
Expand Down Expand Up @@ -64,7 +67,7 @@ const QueryInput = () => {
fetch(proxy + urlToSend, {
// mode: 'no-cors',
headers: {
// 'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
})
Expand Down
3 changes: 2 additions & 1 deletion electron.js
Expand Up @@ -19,7 +19,8 @@ app.on('ready', () => {
// load html into the window
console.log('Dev environment on: ', isDev);
mainWindow.loadURL(url.format({
pathname: isDev ? '//localhost:8080' : path.join(__dirname, './build/index.html'),
// ssiwtched back to 3000 from 8080 because no longer using server
pathname: isDev ? '//localhost:3000' : path.join(__dirname, './build/index.html'),
protocol: isDev ? 'http:' : 'file:',
slashes: true,
}));
Expand Down
8 changes: 6 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -9,8 +9,8 @@
"electron-build": "electron-builder",
"server": "node_modules/nodemon/bin/nodemon.js server/server.js",
"clean-build": "rm -rf build/ .cache dist/",
"react-start": "parcel -p 3000 index.html --out-dir build",
"react-build": "parcel build index.html --out-dir build --public-url ./",
"react-start": "NODE_ENV=development parcel -p 3000 index.html --out-dir build",
"react-build": "NODE_ENV=production parcel build index.html --out-dir build --public-url ./",
"server-test": "npm run react-start & wait-on http://localhost:3000 && npm run server & wait-on http://localhost:8080 && ELECTRON_IS_DEV=1 npm run start-electron",
"start": "npm run react-start & wait-on http://localhost:3000 && ELECTRON_IS_DEV=1 npm run start-electron",
"build": "npm run clean-build && npm run react-build && npm run electron-build && ELECTRON_IS_DEV=0 npm run start-electron",
Expand Down Expand Up @@ -38,11 +38,13 @@
"codemirror": "^5.48.2",
"cors": "^2.8.5",
"css-loader": "^3.1.0",
"dotenv": "^8.0.0",
"express": "^4.17.1",
"grap": "^1.0.0",
"graphql": "^14.4.2",
"graphql-anywhere": "^4.2.4",
"graphql-tag": "^2.10.1",
"node-fetch": "^2.6.0",
"nodemon": "^1.19.1",
"react": "^16.8.6",
"react-apollo": "^2.5.8",
Expand Down

0 comments on commit 88eb3db

Please sign in to comment.