Commit 96cda76543ba1d62975961bf92e6c5072d8d9f30
1 parent
427d64e0
Exists in
master
and in
8 other branches
Use flag to config environment
Showing
1 changed file
with
39 additions
and
20 deletions
Show diff stats
gulp/server.js
| ... | ... | @@ -16,7 +16,7 @@ function browserSyncInit(baseDir, browser) { |
| 16 | 16 | browser = browser === undefined ? 'default' : browser; |
| 17 | 17 | |
| 18 | 18 | var routes = null; |
| 19 | - if(baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) { | |
| 19 | + if (baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) { | |
| 20 | 20 | routes = { |
| 21 | 21 | '/bower_components': 'bower_components' |
| 22 | 22 | }; |
| ... | ... | @@ -34,29 +34,48 @@ function browserSyncInit(baseDir, browser) { |
| 34 | 34 | * |
| 35 | 35 | * For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.0.5/README.md |
| 36 | 36 | */ |
| 37 | - if(gutil.env.target) { | |
| 38 | - server.middleware = proxyMiddleware(['/api/**', '/image_uploads/**'], { | |
| 39 | - target: gutil.env.target, | |
| 40 | - changeOrigin: true, | |
| 41 | - proxyTable: { | |
| 42 | - 'localhost:3000' : gutil.env.target | |
| 43 | - } | |
| 44 | - | |
| 45 | - }); | |
| 46 | - } else { | |
| 47 | - // no target! Point to localhost | |
| 37 | + if (gutil.env.local) { | |
| 38 | + // no target env. Point to localhost | |
| 48 | 39 | server.middleware = proxyMiddleware('/api', { |
| 49 | 40 | target: 'http://0.0.0.0:9000/', |
| 50 | 41 | pathRewrite: { |
| 51 | - // rewrite paths | |
| 52 | - '^/api/v1/articles' : '/articles' | |
| 42 | + // rewrite paths | |
| 43 | + '^/api/v1/articles': '/articles' | |
| 53 | 44 | }, |
| 54 | 45 | proxyTable: { |
| 55 | 46 | // when request.headers.host == 'dev.localhost:3000', |
| 56 | 47 | // override target 'http://www.example.org' to 'http://localhost:8000' |
| 57 | 48 | // 'dev.localhost:3000' : 'http://localhost:8000' |
| 58 | - 'hom.dialoga.gov.br' : 'http://localhost:9000', | |
| 59 | - 'login.dialoga.gov.br' : 'http://localhost:9000' | |
| 49 | + 'hom.dialoga.gov.br': 'http://localhost:9000', | |
| 50 | + 'login.dialoga.gov.br': 'http://localhost:9000' | |
| 51 | + } | |
| 52 | + }); | |
| 53 | + } | |
| 54 | + | |
| 55 | + if (gutil.env.production) { | |
| 56 | + var host_production = 'http://login.dialoga.gov.br/'; | |
| 57 | + server.middleware = proxyMiddleware([ | |
| 58 | + '/api/**', | |
| 59 | + '/image_uploads/**' | |
| 60 | + ], { | |
| 61 | + target: host_production, | |
| 62 | + changeOrigin: true, | |
| 63 | + proxyTable: { | |
| 64 | + 'localhost:3000': host_production | |
| 65 | + } | |
| 66 | + }); | |
| 67 | + } | |
| 68 | + | |
| 69 | + if (gutil.env.staging) { | |
| 70 | + var host_staging = 'http://hom.login.dialoga.gov.br/'; | |
| 71 | + server.middleware = proxyMiddleware([ | |
| 72 | + '/api/**', | |
| 73 | + '/image_uploads/**' | |
| 74 | + ], { | |
| 75 | + target: host_staging, | |
| 76 | + changeOrigin: true, | |
| 77 | + proxyTable: { | |
| 78 | + 'localhost:3000': host_staging | |
| 60 | 79 | } |
| 61 | 80 | }); |
| 62 | 81 | } |
| ... | ... | @@ -73,18 +92,18 @@ browserSync.use(browserSyncSpa({ |
| 73 | 92 | selector: '[ng-app]'// Only needed for angular apps |
| 74 | 93 | })); |
| 75 | 94 | |
| 76 | -gulp.task('serve', ['watch'], function () { | |
| 95 | +gulp.task('serve', ['watch'], function() { | |
| 77 | 96 | browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]); |
| 78 | 97 | }); |
| 79 | 98 | |
| 80 | -gulp.task('serve:dist', ['build'], function () { | |
| 99 | +gulp.task('serve:dist', ['build'], function() { | |
| 81 | 100 | browserSyncInit(conf.paths.dist); |
| 82 | 101 | }); |
| 83 | 102 | |
| 84 | -gulp.task('serve:e2e', ['inject'], function () { | |
| 103 | +gulp.task('serve:e2e', ['inject'], function() { | |
| 85 | 104 | browserSyncInit([conf.paths.tmp + '/serve', conf.paths.src], []); |
| 86 | 105 | }); |
| 87 | 106 | |
| 88 | -gulp.task('serve:e2e-dist', ['build'], function () { | |
| 107 | +gulp.task('serve:e2e-dist', ['build'], function() { | |
| 89 | 108 | browserSyncInit(conf.paths.dist, []); |
| 90 | 109 | }); | ... | ... |