【发布时间】:2019-06-11 22:29:38
【问题描述】:
我是浏览器同步和 gulp 的新手,但根据使用情况,我试图让我的 http-server 可以通过网络服务器访问。此外,我想通过对文件属性使用否定来排除一些要隐藏或不被浏览的目录,但它不起作用......我的主要目标是定义一些目录以一如既往地提供 404 向他们请求的任何内容......
有人可以检查一下吗?如果可能的话,这是我的 gulp 实现:
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var files = ['d2cvib/output/**/*.{xml}','!d2cvib/changed-list/**'];
// Static server
gulp.task('browser-sync', function() {
browserSync.init({files,
port: 8203,
server: {
baseDir: "/mule_local_exchange/d2c/",
middleware: [
function(req, res, next) {
const user = 'd2c';
const pass = 'd2cweb';
let authorized = false;
// See if authorization exist in the request and matches username/password
if (req.headers.authorization) {
const credentials = new Buffer(req.headers.authorization.replace('Basic ', ''), 'base64').toString().split(/:(.*)/)
if (credentials[0] === user && credentials[1] === pass) {
authorized = true;
}
}
if (authorized) {
// Proceed to fulfill the request
next();
} else {
// Authorization doesn't exist / doesn't match, send authorization request in the response header
res.writeHead(401, {'WWW-Authenticate': 'Basic realm="Authenticate"'})
res.end();
}
}
],
directory: true
}
});
});
【问题讨论】:
标签: node.js gulp browser-sync