Skip to content

Commit 8ee8612

Browse files
committed
#20 - Set environment variables to use the dev or prod server
1 parent 92335ab commit 8ee8612

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
package-lock.json
33
.idea*
4+
.env

dist/RNAcentral-sequence-search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/RNAcentral-sequence-search.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"homepage": "https://github.com/RNAcentral/rnacentral-sequence-search-embed#readme",
4646
"dependencies": {
4747
"animate.css": "^3.5.2",
48+
"dotenv": "^8.2.0",
4849
"foundation-sites": "^6.5.0-rc.4",
4950
"jquery": "^3.3.1",
5051
"md5": "^2.2.1",

src/services/routes.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// let server = 'https://search.rnacentral.org';
2-
let server = 'http://51.179.208.74:8002';
1+
let server = process.env.REACT_APP_BRANCH === 'dev' ? 'http://51.179.208.74:8002' : 'https://search.rnacentral.org';
2+
let ebiDevOrProd = process.env.REACT_APP_BRANCH === 'dev' ? 'wwwdev' : 'www';
33

44
module.exports = {
55
rnacentralDatabases: () => `${server}/api/rnacentral-databases`,
@@ -12,5 +12,5 @@ module.exports = {
1212
consumersStatuses: () => `${server}/api/consumers-statuses`,
1313
infernalJobStatus: (jobId) => `${server}/api/infernal-status/${jobId}`,
1414
infernalJobResult: (resultId) => `${server}/api/infernal-result/${resultId}`,
15-
searchEndpoint: (query) => `https://wwwdev.ebi.ac.uk/ebisearch/ws/rest/rnacentral?query=${query}&fields=description,url&format=json&sort=boost:descending`,
15+
searchEndpoint: (query) => `https://${ebiDevOrProd}.ebi.ac.uk/ebisearch/ws/rest/rnacentral?query=${query}&fields=description,url&format=json&sort=boost:descending`,
1616
};

webpack.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
22
const webpack = require('webpack');
3+
const dotenv = require('dotenv');
34

45
const HtmlWebpackPlugin = require('html-webpack-plugin');
56
const ExtractTextPlugin = require('extract-text-webpack-plugin');
@@ -12,6 +13,15 @@ module.exports = function(env) {
1213
if (env && env.prod) environment = 'production';
1314
else environment = 'development';
1415

16+
// call dotenv and it will return an Object with a parsed key
17+
const branch = dotenv.config().parsed;
18+
19+
// reduce it to a nice object
20+
const envKeys = Object.keys(branch).reduce((prev, next) => {
21+
prev[`process.env.${next}`] = JSON.stringify(branch[next]);
22+
return prev;
23+
}, {});
24+
1525
return {
1626
target: 'web',
1727
entry: path.join(__dirname, 'src', 'app.jsx'),
@@ -31,7 +41,8 @@ module.exports = function(env) {
3141
template: "src/index.html",
3242
filename: environment === 'production' ? path.join(__dirname, "index.html") : "index.html"
3343
}),
34-
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', jquery: 'jquery' })
44+
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', jquery: 'jquery' }),
45+
new webpack.DefinePlugin(envKeys)
3546
],
3647
module: {
3748
rules: [

0 commit comments

Comments
 (0)