· 9 years ago · Sep 14, 2016, 09:14 PM
1gulp.task('serve', function() {
2 runSequence('wiredep:test', 'wiredep:app', 'ngconstant:dev', function () {
3 var baseUri = 'http://localhost:' + yeoman.apiPort;
4 // Routes to proxy to the backend. Routes ending with a / will setup
5 // a redirect so that if accessed without a trailing slash, will
6 // redirect. This is required for some endpoints for proxy-middleware
7 // to correctly handle them.
8 var proxyRoutes = [
9 '/api',
10 '/health',
11 '/configprops',
12 '/v2/api-docs',
13 '/swagger-ui',
14 '/configuration/security',
15 '/configuration/ui',
16 '/swagger-resources',
17 '/metrics',
18 '/websocket/tracker',
19 '/dump',
20 '/oauth/token'
21 ];
22
23 var requireTrailingSlash = proxyRoutes.filter(function (r) {
24 return endsWith(r, '/');
25 }).map(function (r) {
26 // Strip trailing slash so we can use the route to match requests
27 // with non trailing slash
28 return r.substr(0, r.length - 1);
29 });
30
31
32
33 var proxies = [
34 // Ensure trailing slash in routes that require it
35 function (req, res, next) {
36 requireTrailingSlash.forEach(function(route){
37 if (url.parse(req.url).path === route) {
38 res.statusCode = 301;
39 res.setHeader('Location', route + '/');
40 res.end();
41 }
42 });
43
44 next();
45 }
46 ].concat(
47 // Build a list of proxies for routes: [route1_proxy, route2_proxy, ...]
48 proxyRoutes.map(function (r) {
49 var options = url.parse(baseUri + r);
50 options.route = r;
51 return proxy(options);
52 }));
53
54 browserSync({
55 open: false,
56 port: yeoman.port,
57 server: {
58 baseDir: yeoman.app,
59 middleware: proxies
60 }
61 });
62
63 gulp.run('watch');
64 });
65});
66
67gulp.task('serve', () => {
68 const config = require('./webpack.dev.config');
69 config.entry.app = [
70 // this modules required to make HRM working
71 // it responsible for all this webpack magic
72 'webpack-hot-middleware/client?reload=true',
73 // application entry point
74 ].concat(paths.entry);
75
76 var compiler = webpack(config);
77
78 serve({
79 port: process.env.PORT || 3000,
80 open: false,
81 server: {baseDir: root},
82 middleware: [
83 historyApiFallback(),
84 webpackDevMiddleware(compiler, {
85 stats: {
86 colors: colorsSupported,
87 chunks: false,
88 modules: false
89 },
90 publicPath: config.output.publicPath
91 }),
92 webpackHotMiddleware(compiler)
93 ]
94 });
95});