server.js
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'use strict';
var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var browserSync = require('browser-sync');
var browserSyncSpa = require('browser-sync-spa');
var util = require('util');
var gutil = require('gulp-util');
var proxyMiddleware = require('http-proxy-middleware');
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)) {
routes = {
'/bower_components': 'bower_components'
};
}
var server = {
baseDir: baseDir,
routes: routes
};
/*
* You can add a proxy to your backend by uncommenting the line bellow.
* You just have to configure a context which will we redirected and the target url.
* Example: $http.get('/users') requests will be automatically proxified.
*
* For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.0.5/README.md
*/
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'
},
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'
}
});
}
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
}
});
}
browserSync.instance = browserSync.init({
startPath: '/',
server: server,
browser: browser,
ghostMode: false,
scrollRestoreTechnique: 'cookie'
});
}
browserSync.use(browserSyncSpa({
selector: '[ng-app]'// Only needed for angular apps
}));
gulp.task('serve', ['watch'], function() {
browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]);
});
gulp.task('serve:dist', ['build'], function() {
browserSyncInit(conf.paths.dist);
});
gulp.task('serve:e2e', ['inject'], function() {
browserSyncInit([conf.paths.tmp + '/serve', conf.paths.src], []);
});
gulp.task('serve:e2e-dist', ['build'], function() {
browserSyncInit(conf.paths.dist, []);
});