lemur/gulp/server.js

64 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2015-06-22 22:47:27 +02:00
'use strict';
var gulp = require('gulp');
2021-01-11 19:39:27 +01:00
const watch = require('./watch')
2015-06-22 22:47:27 +02:00
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
});
}
2021-01-11 19:39:27 +01:00
gulp.task('serve', gulp.series(['watch'], function (done) {
2015-06-22 22:47:27 +02:00
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'
]);
2021-01-11 19:39:27 +01:00
done();
}));
2015-06-22 22:47:27 +02:00
2021-01-11 19:39:27 +01:00
gulp.task('serve:dist', gulp.series(['build'], function (done) {
2015-06-22 22:47:27 +02:00
browserSyncInit('lemur/static/dist');
2021-01-11 19:39:27 +01:00
done();
}));