Skip to content

Commit a29089e

Browse files
committed
Use webpack DefinePlugin to set server url
1 parent 8937f26 commit a29089e

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"$": true,
2323
"ga": true,
2424
"jQuery": true,
25-
"router": true
25+
"router": true,
26+
"__BASEURL__": false
2627
},
2728
"rules": {
2829
"comma-dangle": 2,

client/actions/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const AUTH_USER = 'auth_user';
1919
export const UNAUTH_USER = 'unauth_user';
2020
export const INVENTORY_ERROR = 'inventory_error';
2121

22-
const ROOT_URL = 'http://localhost:3000/api';
22+
const ROOT_URL = __BASEURL__;
2323

2424
const getAxiosConfig = () => {
2525
const token = localStorage.getItem('token');

client/actions/validate_user_fields.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const VALIDATE_USER_FIELDS_SUCCESS = 'VALIDATE_USER_FIELDS_SUCCESS';
66
export const VALIDATE_USER_FIELDS_FAILURE = 'VALIDATE_USER_FIELDS_FAILURE';
77
export const RESET_VALIDATE_USER_FIELDS = 'RESET_VALIDATE_USER_FIELDS';
88

9-
const ROOT_URL = 'http://localhost:3000/api';
9+
const ROOT_URL = __BASEURL__;
1010

1111
export function validateUserFieldsSuccess() {
1212
return {

gulpfile.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const gulp = require('gulp');
44
const eslint = require('gulp-eslint');
5-
const webpack = require('webpack-stream');
5+
const webpack = require('webpack');
6+
const webpackStream = require('webpack-stream');
67
const sass = require('gulp-sass');
78
const mocha = require('gulp-mocha');
89

@@ -30,7 +31,7 @@ gulp.task('sass:dev', () => {
3031
});
3132

3233
gulp.task('build:dev', () => {
33-
webpack({
34+
webpackStream({
3435
entry: ['./client/index.js'],
3536
output: {
3637
filename: 'bundle.js'
@@ -44,6 +45,13 @@ gulp.task('build:dev', () => {
4445
}
4546
]
4647
},
48+
plugins: [
49+
new webpack.DefinePlugin({
50+
__BASEURL__: JSON.stringify(process.env.SERVER_ENV === 'production' ?
51+
`http://${process.env.HEROKU_APP_NAME}.herokuapp.com` :
52+
'http://localhost:3000')
53+
})
54+
],
4755
devtool: 'source-map'
4856
})
4957
.pipe(gulp.dest('dist/'));

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"redux-form": "^5.0.1",
7676
"redux-thunk": "^2.0.1",
7777
"sinon": "^1.17.4",
78+
"webpack": "^1.13.0",
7879
"webpack-stream": "^3.1.0"
7980
}
8081
}

0 commit comments

Comments
 (0)