From 446543c6c48f690fde87d3f44176eff49010aff3 Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Fri, 2 Oct 2015 18:24:44 -0400 Subject: [PATCH] Use thumbnail image host from process.env Limit built process.env to keys in src/env.json, which serves as a source for defaults. --- src/components/carousel/carousel.jsx | 2 +- src/env.json | 3 +++ webpack.config.js | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/env.json diff --git a/src/components/carousel/carousel.jsx b/src/components/carousel/carousel.jsx index f025eb86b..b64412914 100644 --- a/src/components/carousel/carousel.jsx +++ b/src/components/carousel/carousel.jsx @@ -33,7 +33,7 @@ module.exports = React.createClass({ {this.props.items.map(function (item) { var thumbnailUrl = ( - '//cdn2.scratch.mit.edu/get_image/' + item.type + '/' + item.id + '_' + + process.env.IMAGE_HOST + '/get_image/' + item.type + '/' + item.id + '_' + this.typeDimensions[item.type][0] + 'x' + this.typeDimensions[item.type][1] + '.png' + '?v=' + item.thumbnailVersion ); diff --git a/src/env.json b/src/env.json new file mode 100644 index 000000000..8d29113b5 --- /dev/null +++ b/src/env.json @@ -0,0 +1,3 @@ +{ + "IMAGE_HOST": "//cdn2.scratch.mit.edu" +} diff --git a/webpack.config.js b/webpack.config.js index 3e5862e60..4da1ab535 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,7 @@ var path = require('path'); var webpack = require('webpack'); var routes = require('./server/routes.json'); +var buildEnv = require('./src/env.json'); // Prepare all entry points var entry = { @@ -48,6 +49,12 @@ module.exports = { ] }, plugins: [ + new webpack.DefinePlugin({ + 'process.env': Object.keys(buildEnv).reduce(function (env, key) { + env[key] = JSON.stringify(process.env[key] || env[key]); + return env; + }, buildEnv) + }), new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false