diff --git a/gulp/server.js b/gulp/server.js index 794e5c2..fc5dea2 100644 --- a/gulp/server.js +++ b/gulp/server.js @@ -16,7 +16,7 @@ function browserSyncInit(baseDir, browser) { browser = browser === undefined ? 'default' : browser; var routes = null; - if(baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) { + if (baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) { routes = { '/bower_components': 'bower_components' }; @@ -34,29 +34,48 @@ function browserSyncInit(baseDir, browser) { * * For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.0.5/README.md */ - if(gutil.env.target) { - server.middleware = proxyMiddleware(['/api/**', '/image_uploads/**'], { - target: gutil.env.target, - changeOrigin: true, - proxyTable: { - 'localhost:3000' : gutil.env.target - } - - }); - } else { - // no target! Point to localhost + if (gutil.env.local) { + // no target env. Point to localhost server.middleware = proxyMiddleware('/api', { target: 'http://0.0.0.0:9000/', pathRewrite: { - // rewrite paths - '^/api/v1/articles' : '/articles' + // rewrite paths + '^/api/v1/articles': '/articles' }, proxyTable: { // when request.headers.host == 'dev.localhost:3000', // override target 'http://www.example.org' to 'http://localhost:8000' // 'dev.localhost:3000' : 'http://localhost:8000' - 'hom.dialoga.gov.br' : 'http://localhost:9000', - 'login.dialoga.gov.br' : 'http://localhost:9000' + 'hom.dialoga.gov.br': 'http://localhost:9000', + 'login.dialoga.gov.br': 'http://localhost:9000' + } + }); + } + + if (gutil.env.production) { + var host_production = 'http://login.dialoga.gov.br/'; + server.middleware = proxyMiddleware([ + '/api/**', + '/image_uploads/**' + ], { + target: host_production, + changeOrigin: true, + proxyTable: { + 'localhost:3000': host_production + } + }); + } + + if (gutil.env.staging) { + var host_staging = 'http://hom.login.dialoga.gov.br/'; + server.middleware = proxyMiddleware([ + '/api/**', + '/image_uploads/**' + ], { + target: host_staging, + changeOrigin: true, + proxyTable: { + 'localhost:3000': host_staging } }); } @@ -73,18 +92,18 @@ browserSync.use(browserSyncSpa({ selector: '[ng-app]'// Only needed for angular apps })); -gulp.task('serve', ['watch'], function () { +gulp.task('serve', ['watch'], function() { browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]); }); -gulp.task('serve:dist', ['build'], function () { +gulp.task('serve:dist', ['build'], function() { browserSyncInit(conf.paths.dist); }); -gulp.task('serve:e2e', ['inject'], function () { +gulp.task('serve:e2e', ['inject'], function() { browserSyncInit([conf.paths.tmp + '/serve', conf.paths.src], []); }); -gulp.task('serve:e2e-dist', ['build'], function () { +gulp.task('serve:e2e-dist', ['build'], function() { browserSyncInit(conf.paths.dist, []); }); -- libgit2 0.21.2