-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsProxy.js
63 lines (55 loc) · 1.83 KB
/
bsProxy.js
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
/*
* Proxy Live site and inject local files
* - run 'npm install --save-dev browser-sync'
* - change the varables below as needed
* - 'node bsProxy' to run the task
*/
//
//initialize all of our variables
var PATH_STRING, PROXY, ASSETS_DIR, REMOTE_ASSETS_PATH, REGEX, browserSync, serveStatic;
// Url of the site to be proxied
PROXY = 'www.lmmontgomery.ca';
// Root assets folder (contains /css/, /js/ etc)
ASSETS_DIR = 'dist/assets';
// Path on server to remote assets folder (escape the slashes; no trailing slash)
//REMOTE_ASSETS_PATH = 'http://www.lmmontgomery.ca/sites/www.lmmontgomery.ca/themes/lmmi_2015';
REMOTE_ASSETS_PATH = 'http://www.lmmontgomery.ca/sites/www.lmmontgomery.ca/themes/lmmi_2015/dist/assets';
PATH_STRING = REMOTE_ASSETS_PATH.replace(/\//g, '\\/');
//PATH_STRING = 'www.lmmontgomery.ca';
//===================================
// Includes and vars
browserSync = require('browser-sync');
serveStatic = require('serve-static');
//REGEX = new RegExp( PATH_STRING, 'g');
REGEX = new RegExp( PATH_STRING, 'g');
//===================================
/*
* Browsersync Task
*
*/
browserSync({
// proxy live site
proxy: PROXY,
// serve up these local files
serveStatic: [ASSETS_DIR],
//logLevel: "debug",
//logFileChanges: true,
//open: false,
injectChanges: true,
////// Watch this stuff for changes and inject it if it does
//files: ASSETS_DIR + '/**',
//// modify url of the remote assets so they point to the locally served version
//[>
rewriteRules: [
{
//match: /REMOTE_ASSETS_PATH/g,
match: REGEX,
fn: function(matched) { return '' }
//match: REGEX,
//fn: function (req, res, match) {
//return '';
//}
}
]
});
console.log(PATH_STRING);