From 2b6c7a4025fdeccf8de61392ff058922bc980a97 Mon Sep 17 00:00:00 2001 From: Pranav Raj Sreepuram Date: Sun, 18 Aug 2019 00:44:44 +0530 Subject: [PATCH] Add env variables for frontend --- .env.sample | 4 ++++ .gitignore | 3 +++ README.md | 3 +++ app/javascript/src/constants.js | 2 +- app/javascript/src/routes/index.js | 1 - config/webpack/development.js | 3 +++ config/webpack/environment.js | 12 ++++++++++++ package.json | 1 + yarn.lock | 18 ++++++++++++++++++ 9 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 000000000..3cebf7270 --- /dev/null +++ b/.env.sample @@ -0,0 +1,4 @@ +pusher_cluster= +pusher_key= + +fb_app_id= diff --git a/.gitignore b/.gitignore index 4dd0265d8..544bff25e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ config/database.yml node_modules *.rdb + +# Ignore env files +.env diff --git a/README.md b/README.md index 2c82bd6c3..f538422ad 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ bundle # copy database config cp shared/config/database.yml config/database.yml +# copy frontend env file +cp .env.sample .env + # run db migrations bundle exec rake db:migrate diff --git a/app/javascript/src/constants.js b/app/javascript/src/constants.js index 77171da7c..38a52274e 100644 --- a/app/javascript/src/constants.js +++ b/app/javascript/src/constants.js @@ -1,6 +1,6 @@ export default { APP_BASE_URL: '/', - PUSHER: 'test', + PUSHER: __PUSHER__, get apiURL() { return `${this.APP_BASE_URL}/`; }, diff --git a/app/javascript/src/routes/index.js b/app/javascript/src/routes/index.js index 5ea19530e..d080a5385 100644 --- a/app/javascript/src/routes/index.js +++ b/app/javascript/src/routes/index.js @@ -59,7 +59,6 @@ const authIgnoreRoutes = [ const redirectUser = (to, from, next) => { - console.log(to); // If auth ignore go to page if (authIgnoreRoutes.indexOf(to.name) > -1) { return next(); diff --git a/config/webpack/development.js b/config/webpack/development.js index c5edff94a..203c6a64e 100644 --- a/config/webpack/development.js +++ b/config/webpack/development.js @@ -1,5 +1,8 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development' +const dotenv = require('dotenv') +dotenv.config({ path: '.env', silent: true }) + const environment = require('./environment') module.exports = environment.toWebpackConfig() diff --git a/config/webpack/environment.js b/config/webpack/environment.js index 7f7627d50..07c064bcc 100644 --- a/config/webpack/environment.js +++ b/config/webpack/environment.js @@ -2,6 +2,8 @@ const { environment } = require('@rails/webpacker') const { VueLoaderPlugin } = require('vue-loader') const vue = require('./loaders/vue') const path = require('path') +const webpack = require('webpack') + environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin()) environment.loaders.prepend('vue', vue) environment.loaders.append('audio', { @@ -24,4 +26,14 @@ const resolve = { environment.config.merge({ resolve }); +const { pusher_cluster: cluster, pusher_key: token, fb_app_id: fbAppID } = process.env + +environment.plugins.prepend('DefinePlugin', new webpack.DefinePlugin({ + __PUSHER__: { + token: `"${token}"`, + cluster: `"${cluster}"`, + }, + __FB_ID__: `"${fbAppID}"`, +})) + module.exports = environment diff --git a/package.json b/package.json index 053e035b3..a1f287784 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "axios": "~0.15.3", "bourbon": "~4.2.7", "chart.js": "~2.5.0", + "dotenv": "^8.0.0", "emojione": "~2.2.7", "foundation-sites": "6.3.0", "ionicons": "~3.0.0", diff --git a/yarn.lock b/yarn.lock index 9e815dbe6..338d941ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2872,6 +2872,11 @@ dot-prop@^4.1.1: dependencies: is-obj "^1.0.0" +dotenv@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.0.0.tgz#ed310c165b4e8a97bb745b0a9d99c31bda566440" + integrity sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg== + duplexify@^3.4.2, duplexify@^3.6.0: version "3.7.1" resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.7.1.tgz#2a4df5317f6ccfd91f86d6fd25d8d8a103b88309" @@ -4391,6 +4396,11 @@ lodash._reinterpolate@~3.0.0: resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= +lodash.defaults@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c" + integrity sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw= + lodash.get@^4.0: version "4.4.2" resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" @@ -6219,6 +6229,14 @@ querystringify@^2.1.1: resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.1.1.tgz#60e5a5fd64a7f8bfa4d2ab2ed6fdf4c85bad154e" integrity sha512-w7fLxIRCRT7U8Qu53jQnJyPkYZIaR4n5151KMfcJlO/A9397Wxb1amJvROTK6TOnp7PfoAmg/qXiNHI+08jRfA== +rails-erb-loader@^5.5.2: + version "5.5.2" + resolved "https://registry.yarnpkg.com/rails-erb-loader/-/rails-erb-loader-5.5.2.tgz#db3fa8ac89600f09d179a1a70a2ca18c592576ea" + integrity sha512-cjQH9SuSvRPhnWkvjmmAW/S4AFVDfAtYnQO4XpKJ8xpRdZayT73iXoE+IPc3VzN03noZXhVmyvsCvKvHj4LY6w== + dependencies: + loader-utils "^1.1.0" + lodash.defaults "^4.2.0" + randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5: version "2.1.0" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a"