Enable gulp server to proxy backend
This commit is contained in:
parent
dfadcc52ef
commit
47595e2073
|
@ -6,31 +6,31 @@ var browserSync = require('browser-sync');
|
||||||
var httpProxy = require('http-proxy');
|
var httpProxy = require('http-proxy');
|
||||||
|
|
||||||
/* This configuration allow you to configure browser sync to proxy your backend */
|
/* This configuration allow you to configure browser sync to proxy your backend */
|
||||||
/*
|
|
||||||
var proxyTarget = 'http://localhost/context/'; // The location of your backend
|
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
|
var proxyApiPrefix = '/api/'; // The element in the URL which differentiate between API request and static file request
|
||||||
var proxy = httpProxy.createProxyServer({
|
var proxy = httpProxy.createProxyServer({
|
||||||
target: proxyTarget
|
target: proxyTarget
|
||||||
});
|
});
|
||||||
function proxyMiddleware(req, res, next) {
|
function proxyMiddleware(req, res, next) {
|
||||||
if (req.url.indexOf(proxyApiPrefix) !== -1) {
|
if (req.url.indexOf(proxyApiPrefix) !== -1) {
|
||||||
proxy.web(req, res);
|
proxy.web(req, res);
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
function browserSyncInit(baseDir, files, browser) {
|
function browserSyncInit(baseDir, files, browser) {
|
||||||
browser = browser === undefined ? 'default' : browser;
|
browser = browser === undefined ? 'default' : browser;
|
||||||
|
|
||||||
browserSync.instance = browserSync.init(files, {
|
browserSync.instance = browserSync.init(files, {
|
||||||
startPath: '/index.html',
|
startPath: '/index.html',
|
||||||
server: {
|
server: {
|
||||||
baseDir: baseDir,
|
middleware: [proxyMiddleware],
|
||||||
routes: {
|
baseDir: baseDir,
|
||||||
'/bower_components': './bower_components'
|
routes: {
|
||||||
}
|
'/bower_components': './bower_components'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
browser: browser,
|
browser: browser,
|
||||||
ghostMode: false
|
ghostMode: false
|
||||||
|
|
Loading…
Reference in New Issue