lemur/gulp/server.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-06-22 22:47:27 +02:00
'use strict';
var gulp = require('gulp');
var browserSync = require('browser-sync');
2018-08-22 22:21:35 +02:00
var httpProxy = require('http-proxy');
2015-06-22 22:47:27 +02:00
/* This configuration allow you to configure browser sync to proxy your backend */
2019-05-01 01:21:54 +02:00
var proxyTarget = 'http://localhost:8000/'; // The location of your backend
var proxyApiPrefix = '/api/'; // The element in the URL which differentiate between API request and static file request
2015-06-22 22:47:27 +02:00
var proxy = httpProxy.createProxyServer({
2019-05-01 01:21:54 +02:00
target: proxyTarget
2015-06-22 22:47:27 +02:00
});
function proxyMiddleware(req, res, next) {
2019-05-01 01:21:54 +02:00
if (req.url.indexOf(proxyApiPrefix) !== -1) {
proxy.web(req, res);
} else {
next();
}
2015-06-22 22:47:27 +02:00
}
function browserSyncInit(baseDir, files, browser) {
browser = browser === undefined ? 'default' : browser;
browserSync.instance = browserSync.init(files, {
startPath: '/index.html',
2019-05-01 01:21:54 +02:00
server: {
middleware: [proxyMiddleware],
baseDir: baseDir,
routes: {
'/bower_components': './bower_components'
}
2015-06-22 22:47:27 +02:00
},
browser: browser,
ghostMode: false
});
}
gulp.task('serve', ['watch'], function () {
browserSyncInit([
'.tmp',
'lemur/static/app'
2015-06-22 22:47:27 +02:00
], [
'.tmp/*.html',
'.tmp/styles/**/*.css',
'lemur/static/app/angular/**/*.js',
'lemur/static/app/partials/**/*.html',
'lemur/static/app/images/**/*',
'lemur/static/app/angular/**/*',
'lemur/static/app/index.html'
]);
});
gulp.task('serve:dist', ['build'], function () {
browserSyncInit('lemur/static/dist');
});