解釋:給gulp-connect 增加一個中間件誊薄,配置下選項即可堡赔。
var localhostServer = require('gulp-connect');
//資源文件跨域配置
var cors = function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
};
//運行的時候要sudo權(quán)限
gulp.task('localhostServer', function () {
localhostServer.server({
port: 443,
//port: 80,
https: true,
host: 'r03.haha.com',
livereload: true,
middleware: function () {
return [cors];
}
});
});