From b025adc6a77fec9c271e14794b2743fda983ec1a Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Tue, 7 Jan 2020 13:03:59 -0800 Subject: [PATCH] stub basic connection --- package.json | 7 +++++-- server/bin/www | 2 +- src/App.js | 4 ++++ src/config.js | 15 +++++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/config.js diff --git a/package.json b/package.json index 391611b..6b60eac 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,14 @@ "socket.io-client": "^2.3.0" }, "scripts": { - "start": "react-scripts start", + "start": "REACT_APP_ENVIRONMENT='development' react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", - "flow": "flow" + "flow": "flow", + + "predeploy": "REACT_APP_ENVIRONMENT=production npm run build" + }, "eslintConfig": { "extends": "react-app" diff --git a/server/bin/www b/server/bin/www index 0a437c1..ec05bde 100755 --- a/server/bin/www +++ b/server/bin/www @@ -12,7 +12,7 @@ var http = require('http'); * Get port from environment and store in Express. */ -var port = normalizePort(process.env.PORT || '3000'); +var port = normalizePort(process.env.PORT || '8000'); app.set('port', port); /** diff --git a/src/App.js b/src/App.js index 739ff0f..241ed97 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,14 @@ import React from 'react'; import './App.scss'; +import config from './config'; function App() { + let fetchData = {}; + fetch(config.apiAddress).then(res => {console.log(res);fetchData = res.body}).then(() => console.log(fetchData)) return (

React Boilerplate

+ {fetchData ?

: <>}
); } diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..d54c463 --- /dev/null +++ b/src/config.js @@ -0,0 +1,15 @@ +const production = { + apiAddress: null +} + +const development = { + apiAddress: 'http://localhost:8000' +} + +const config = process.env.REACT_APP_ENVIRONMENT === 'production' + ? production + : development + +export default { + ...config +} \ No newline at end of file