我正在使用以下代码将网址从CDN替换为本地,但是当我在代理下的公司网络中它不起作用但是当我在没有代理互联网的情况下运行相同的代码时,它按预期工作可以任何人帮助我解决这个问题,因为我无法在我的
中测试我的代码
module.exports = function(grunt) {
var rewriteModule = require('http-rewrite-middleware');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
server: {
options: {
port: 9001,
livereload: true,
middleware: function (connect, options) {
// Setup the proxy
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];
// RewriteRules support
middlewares.push(rewriteModule.getMiddleware([
//rewrite url for SSI includes on UI elements
//{from: '^index.html$', to: '/.tmp/index.html'},
{from: '^/app/(.*).html$', to: '/.tmp/$1.html'}
]));
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
var directory = options.directory || options.base[options.base.length - 1];
options.base.forEach(function (base) {
// Serve static files.
middlewares.push(connect.static(base));
});
// Make directory browse-able.
middlewares.push(connect.directory(directory));
return middlewares;
}
},
proxies: [
{
context: ['/templates', '/css', '/images'],
host: 'wwwtest.google.com',
port: 80,
https: false,
changeOrigin: false
},
{
context: ['/userCal', '/commonDataCal'],
host: 'wwwtest.google.com',
port: 443,
https: true,
changeOrigin: false
}
]
}
},
ssi: {
options: {
cache: 'all',
baseDir: '.'
},
ui: {
files: [{
expand: true,
cwd: '.tmp',
src: ['index.html', 'development.html'],
dest: '.tmp/',
ext: '.html'
}]
}
},
replace: {
CDN: {
src: ['app/index.html','app/development.html'],
dest: '.tmp/',
replacements: [{
from: 'images.google.com',
to: 'localhost:9001'
}]
}
},
watch: {
files: ['**/*.html'],
tasks: ['replace:CDN', 'ssi']
},
clean: {
build: {
src: ['.tmp']
}
},
jshint: {
files: ['Gruntfile.js', 'app/**/*.js'],
options: {
// options here to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true,
document: true
}
}
}
});
// Load the plugin that provides the above task.
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-connect-proxy');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-ssi');
// Default task(s).
grunt.registerTask('default', []);
grunt.registerTask('server', ['replace:CDN', 'ssi', 'configureProxies:server', 'connect:server', 'watch']);
//you can call the following tasks directly
//grunt jshint
//grunt clean
};