Skip to content

Commit

Permalink
Feat: introduce .env file and delete dynamic configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanCCollins committed Feb 6, 2017
1 parent fe403c4 commit 2f9fc40
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BASE_URL='http://localhost:1337/'
API_URL='http://localhost:3000/'
DEBUG=false
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
app/build/
app/dist/
webpack.config.*.js
webpack.config.js
config/
4 changes: 2 additions & 2 deletions app/src/apolloClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import ApolloClient, {
createNetworkInterface,
addTypeName,
} from 'apollo-client';
import { BASE_URL } from 'config'; // eslint-disable-line

const url = `${BASE_URL}graphql`;
const baseUrl = process.env.API_URL || 'http://localhost:3000';
const url = `${baseUrl}graphql`;

const client = new ApolloClient({
networkInterface: createNetworkInterface({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ exports[`<Navbar /> should render with default props 1`] = `
<div>
<Header
align="center"
colorIndex="neutral"
direction="row"
justify="between"
pad={
Expand Down
12 changes: 0 additions & 12 deletions app/src/config/index.js

This file was deleted.

8 changes: 6 additions & 2 deletions devServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config.js');
const path = require('path');
const env = require('node-env-file');

const PORT = process.env.PORT || 1337;
const IP = process.env.IP || 'localhost';
env(path.join(__dirname, '.env'));

const serverUrl = process.env.BASE_URL || 'http://localhost:1337';
const PORT = serverUrl.match(/\d+/g)[0];
const IP = serverUrl.match(/\w+/g)[1];

new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"markdown-loader": "^0.1.7",
"minimist": "^1.2.0",
"morgan": "^1.7.0",
"node-env-file": "^0.1.8",
"offline-plugin": "^3.4.2",
"react": "^15.1.0",
"react-addons-css-transition-group": "^15.2.1",
Expand Down Expand Up @@ -171,10 +172,10 @@
"css-loader": "^0.23.0",
"eslint": "^3.15.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-import-resolver-webpack": "0.8.0",
"eslint-loader": "^1.1.1",
"eslint-plugin-graphql": "^0.4.0",
"eslint-plugin-import": "^2.2.0",
"eslint-import-resolver-webpack": "0.8.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.9.0",
"expect-jsx": "^2.6.0",
Expand Down
41 changes: 21 additions & 20 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
/* eslint-disable */
/* eslint-disable no-console */
import express from 'express';
import path from 'path';
import morgan from 'morgan';
import React from 'react';
import env from 'node-env-file';
import { renderToString, renderToStaticMarkup } from 'react-dom/server';
import { match, RouterContext } from 'react-router';
import { ApolloProvider } from 'react-apollo';
import { getDataFromTree } from 'react-apollo/server';
import { createNetworkInterface } from 'apollo-client';
import store from '../app/src/store.js';
import { routes } from '../app/src/routes.js';
import { BASE_URL } from '../app/src/config';
import styleSheet from 'styled-components/lib/models/StyleSheet';
import store from '../app/src/store';
import { routes } from '../app/src/routes';
import Html from './utils/Html';
import createApolloClient from './utils/create-apollo-client';
import manifest from './public/manifest.json';
import styleSheet from 'styled-components/lib/models/StyleSheet';

const app = express();
const isDeveloping = process.env.NODE_ENV !== 'production';
env(path.join(__dirname, '..', 'env'));

// Need to set this to your api url
const IP = process.env.IP || 'localhost';
const PORT = process.env.PORT || 1337;
const apiUrl = `${BASE_URL}graphql`;
const app = express();
const serverUrl = process.env.BASE_URL || 'http://localhost:1337';
const apiUrl = process.env.API_URL || 'http://localhost:3000';
const PORT = serverUrl.match(/\d+/g)[0];
const IP = serverUrl.match(/\w+/g)[1];
const graphqlUrl = `${apiUrl}graphql`;
const debug = process.env.DEBUG || false;

app.use(morgan('combined'));
app.use(express.static(__dirname + '/public'));
if (debug) { app.use(morgan('combined')); }
app.use(express.static(path.join(__dirname, '/public')));

app.use((req, res) => {
match({ routes, location: req.url },
Expand All @@ -40,7 +42,7 @@ app.use((req, res) => {
const client = createApolloClient({
ssrMode: true,
networkInterface: createNetworkInterface({
uri: apiUrl,
uri: graphqlUrl,
credentials: 'same-origin',
headers: req.headers,
}),
Expand All @@ -56,19 +58,19 @@ app.use((req, res) => {
const html = (
<Html
content={content}
scriptHash={manifest["/main.js"]}
vendorHash={manifest["/vendor.js"]}
cssHash={manifest["/main.css"]}
scriptHash={manifest['/main.js']}
vendorHash={manifest['/vendor.js']}
cssHash={manifest['/main.css']}
styles={styles}
state={ctx.store.getState()}
/>
);
res.status(200).send(`<!doctype html>\n${renderToStaticMarkup(html)}`);
}).catch(e => console.error('RENDERING ERROR:', e)); // eslint-disable-line no-console
}).catch(e => console.error('RENDERING ERROR:', e));
} else {
res.status(404).send('Not found');
}
})
});
});

app.listen(PORT, IP, (err) => {
Expand All @@ -77,4 +79,3 @@ app.listen(PORT, IP, (err) => {
}
return console.info(`==> 😎 Listening on port ${PORT}. Open http://${IP}:${PORT} in your browser.`);
});
/* eslint-enable */
3 changes: 1 addition & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ module.exports = {
components: path.resolve(ROOT_PATH, 'app/src/components'),
containers: path.resolve(ROOT_PATH, 'app/src/containers'),
pages: path.resolve(ROOT_PATH, 'app/src/pages'),
fragments: path.resolve(ROOT_PATH, 'app/src/fragments'),
config: path.resolve(ROOT_PATH, 'app/src/config'),
utils: path.resolve(ROOT_PATH, 'app/src/utils')
},
},
postcss: function () {
Expand Down
3 changes: 1 addition & 2 deletions webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ module.exports = {
components: path.resolve(ROOT_PATH, 'app/src/components'),
containers: path.resolve(ROOT_PATH, 'app/src/containers'),
pages: path.resolve(ROOT_PATH, 'app/src/pages'),
fragments: path.resolve(ROOT_PATH, 'app/src/fragments'),
config: path.resolve(ROOT_PATH, 'app/src/config'),
utils: path.resolve(ROOT_PATH, 'app/src/utils')
},
},
output: {
Expand Down
86 changes: 73 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ babel-code-frame@^6.16.0:
esutils "^2.0.2"
js-tokens "^2.0.0"

babel-code-frame@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4"
dependencies:
chalk "^1.1.0"
esutils "^2.0.2"
js-tokens "^3.0.0"

babel-core@^6.0.0, babel-core@^6.18.0, babel-core@^6.3.15:
version "6.18.2"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.18.2.tgz#d8bb14dd6986fa4f3566a26ceda3964fa0e04e5b"
Expand All @@ -362,15 +370,15 @@ babel-core@^6.0.0, babel-core@^6.18.0, babel-core@^6.3.15:
slash "^1.0.0"
source-map "^0.5.0"

babel-eslint@^6.0.4:
version "6.1.2"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-6.1.2.tgz#5293419fe3672d66598d327da9694567ba6a5f2f"
babel-eslint@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-7.1.1.tgz#8a6a884f085aa7060af69cfc77341c2f99370fb2"
dependencies:
babel-traverse "^6.0.20"
babel-types "^6.0.19"
babylon "^6.0.18"
lodash.assign "^4.0.0"
lodash.pickby "^4.0.0"
babel-code-frame "^6.16.0"
babel-traverse "^6.15.0"
babel-types "^6.15.0"
babylon "^6.13.0"
lodash.pickby "^4.6.0"

babel-generator@^6.18.0:
version "6.18.0"
Expand Down Expand Up @@ -528,6 +536,12 @@ babel-loader@^6.2.0:
mkdirp "^0.5.1"
object-assign "^4.0.1"

babel-messages@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.22.0.tgz#36066a214f1217e4ed4164867669ecb39e3ea575"
dependencies:
babel-runtime "^6.22.0"

babel-messages@^6.8.0:
version "6.8.0"
resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.8.0.tgz#bf504736ca967e6d65ef0adb5a2a5f947c8e0eb9"
Expand Down Expand Up @@ -1055,6 +1069,13 @@ babel-runtime@^6.0.0, babel-runtime@^6.11.6, babel-runtime@^6.9.0, babel-runtime
core-js "^2.4.0"
regenerator-runtime "^0.9.5"

babel-runtime@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.22.0.tgz#1cf8b4ac67c77a4ddb0db2ae1f74de52ac4ca611"
dependencies:
core-js "^2.4.0"
regenerator-runtime "^0.10.0"

babel-template@^6.14.0, babel-template@^6.15.0, babel-template@^6.16.0, babel-template@^6.7.0, babel-template@^6.8.0:
version "6.16.0"
resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.16.0.tgz#e149dd1a9f03a35f817ddbc4d0481988e7ebc8ca"
Expand All @@ -1065,7 +1086,21 @@ babel-template@^6.14.0, babel-template@^6.15.0, babel-template@^6.16.0, babel-te
babylon "^6.11.0"
lodash "^4.2.0"

babel-traverse@^6.0.20, babel-traverse@^6.16.0, babel-traverse@^6.18.0, babel-traverse@^6.3.26:
babel-traverse@^6.15.0:
version "6.22.1"
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.22.1.tgz#3b95cd6b7427d6f1f757704908f2fc9748a5f59f"
dependencies:
babel-code-frame "^6.22.0"
babel-messages "^6.22.0"
babel-runtime "^6.22.0"
babel-types "^6.22.0"
babylon "^6.15.0"
debug "^2.2.0"
globals "^9.0.0"
invariant "^2.2.0"
lodash "^4.2.0"

babel-traverse@^6.16.0, babel-traverse@^6.18.0, babel-traverse@^6.3.26:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.18.0.tgz#5aeaa980baed2a07c8c47329cd90c3b90c80f05e"
dependencies:
Expand All @@ -1079,7 +1114,7 @@ babel-traverse@^6.0.20, babel-traverse@^6.16.0, babel-traverse@^6.18.0, babel-tr
invariant "^2.2.0"
lodash "^4.2.0"

babel-types@^6.0.19, babel-types@^6.13.0, babel-types@^6.14.0, babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.3.24, babel-types@^6.8.0, babel-types@^6.9.0:
babel-types@^6.13.0, babel-types@^6.14.0, babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.3.24, babel-types@^6.8.0, babel-types@^6.9.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.18.0.tgz#1f7d5a73474c59eb9151b2417bbff4e4fce7c3f8"
dependencies:
Expand All @@ -1088,10 +1123,23 @@ babel-types@^6.0.19, babel-types@^6.13.0, babel-types@^6.14.0, babel-types@^6.16
lodash "^4.2.0"
to-fast-properties "^1.0.1"

babylon@^6.0.18, babylon@^6.11.0, babylon@^6.13.0, babylon@^6.3.26:
babel-types@^6.15.0, babel-types@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.22.0.tgz#2a447e8d0ea25d2512409e4175479fd78cc8b1db"
dependencies:
babel-runtime "^6.22.0"
esutils "^2.0.2"
lodash "^4.2.0"
to-fast-properties "^1.0.1"

babylon@^6.11.0, babylon@^6.13.0, babylon@^6.3.26:
version "6.13.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.13.1.tgz#adca350e088f0467647157652bafead6ddb8dfdb"

babylon@^6.15.0:
version "6.15.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.15.0.tgz#ba65cfa1a80e1759b0e89fb562e27dccae70348e"

bail@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/bail/-/bail-1.0.1.tgz#912579de8b391aadf3c5fdf4cd2a0fc225df3bc2"
Expand Down Expand Up @@ -4202,6 +4250,10 @@ js-tokens@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-2.0.0.tgz#79903f5563ee778cc1162e6dcf1a0027c97f9cb5"

js-tokens@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"

js-yaml@^3.4.3, js-yaml@^3.5.1, js-yaml@^3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80"
Expand Down Expand Up @@ -4464,7 +4516,7 @@ lodash.assign@^3.0.0, lodash.assign@^3.2.0:
lodash._createassigner "^3.0.0"
lodash.keys "^3.0.0"

lodash.assign@^4.0.0, lodash.assign@^4.0.3, lodash.assign@^4.0.6, lodash.assign@^4.2.0:
lodash.assign@^4.0.3, lodash.assign@^4.0.6, lodash.assign@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7"

Expand Down Expand Up @@ -4605,7 +4657,7 @@ lodash.pick@^4.2.1, lodash.pick@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"

lodash.pickby@^4.0.0:
lodash.pickby@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff"

Expand Down Expand Up @@ -4923,6 +4975,10 @@ node-emoji@^1.4.1:
dependencies:
string.prototype.codepointat "^0.2.0"

node-env-file:
version "0.1.8"
resolved "https://registry.yarnpkg.com/node-env-file/-/node-env-file-0.1.8.tgz#fccb7b050f735b5a33da9eb937cf6f1ab457fb69"

node-fetch@^1.0.1:
version "1.6.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04"
Expand Down Expand Up @@ -6359,6 +6415,10 @@ regenerate@^1.2.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.1.tgz#0300203a5d2fdcf89116dce84275d011f5903f33"

regenerator-runtime@^0.10.0:
version "0.10.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.1.tgz#257f41961ce44558b18f7814af48c17559f9faeb"

regenerator-runtime@^0.9.5:
version "0.9.6"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.9.6.tgz#d33eb95d0d2001a4be39659707c51b0cb71ce029"
Expand Down

0 comments on commit 2f9fc40

Please sign in to comment.