我正在尝试使用express-ntlm来获取没有身份验证的Windows用户名。
在我的app.js中,我提出以下内容:
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
var ntlm = require('express-ntlm');
app.use(ntlm());
app.use('/search', search);
加载http://localhost:3000/search时,这在node.js中出现401错误 在chrome控制台中:无法加载资源: 无法加载资源:net :: ERR_UNEXPECTED
这里的路由顺序是什么? 感谢。
=========修改为==============
var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var TT = require('./routes/TT');
var KYEC_stat = require('./routes/KYEC_stat');
var ftc = require('./routes/ftc');
var volPerDevice = require('./routes/topVolPerDevice');
var search = require('./routes/search');
var ntlm = require('express-ntlm');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(ntlm());
app.use('/search', search);
app.use('/tt', TT);
app.use('/kyec', KYEC_stat);
app.use('/ftc', ftc);
app.use('/vol', volPerDevice);
app.use('/', routes);
/// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
======= topVolPerDevice.js ================
var config = require('../config.json');
var express = require('express');
var query = require('pg-query');
var assert = require('assert');
var async = require('async');
var url = require('url');
var queryString = require('querystring');
var router = express.Router();
/* Display quantity tested per device id since 2011 using d3 */
/* The query will first select all lot records and their earliest test date (which is the 'P' insertion incoming material quantity);
then use {lotid, lotstartdate} to retrieve all 1st insertion lot records, then add up lots per device;
then return the 1st 20 device id which tops inocming material quantity;
*/
router.get('/', function(req, res) {
query.connectionParameters = config.reportConnStr; //connecting to localhost
var deviceArray = new Array();
var sqlstr = "sdfsfdfsdsfds";
query(sqlstr, function(err, rows, result) {
assert.equal(rows, result.rows);
for (var i = 0; i < rows.length; i++) {
var device = {};
device.name = rows[i].device;
device.value = rows[i].totalqtyout;
deviceArray.push(device);
}
res.render('d3t1', {deviceArray:deviceArray});
});
});
module.exports = router;
=====更新2/25/2015 =============
本周我正在重新访问这个问题,我进一步了解了一下。 我试着在express-ntlm.js中放下一些调试语句,并在firefox中安装了firebug。事实证明,它可能与中间件序列无关。
return function(request, response, next) {
if (!request.connection.id) {
request.connection.id = utils.uuidv4();
}
var auth_headers = request.headers.authorization;
var user = request.connection.ntlm;
....
}
在这里,我的request.connection.ntlm为空。
这可能是什么原因?它是关于浏览器设置还是我的网络设置?
我在公司网络上运行,我在网络域。
答案 0 :(得分:0)
更新:
在app.js中更改为:
app.use(ntlm());
app.use('/', search);
app.use('/', TT);
app.use('/', KYEC_stat);
app.use('/', ftc);
app.use('/', volPerDevice);
app.use('/', routes);
并添加&#39; / vol&#39;在topVolPerDevice文件中的路由器中:
var config = require('../config.json');
var express = require('express');
var query = require('pg-query');
var assert = require('assert');
var async = require('async');
var url = require('url');
var queryString = require('querystring');
var router = express.Router();
/* Display quantity tested per device id since 2011 using d3 */
/* The query will first select all lot records and their earliest test date (which is the 'P' insertion incoming material quantity);
then use {lotid, lotstartdate} to retrieve all 1st insertion lot records, then add up lots per device;
then return the 1st 20 device id which tops inocming material quantity;
*/
router.get('/vol', function(req, res) {
query.connectionParameters = config.reportConnStr; //connecting to localhost
var deviceArray = new Array();
var sqlstr = "sdfsfdfsdsfds";
query(sqlstr, function(err, rows, result) {
assert.equal(rows, result.rows);
for (var i = 0; i < rows.length; i++) {
var device = {};
device.name = rows[i].device;
device.value = rows[i].totalqtyout;
deviceArray.push(device);
}
res.render('d3t1', {deviceArray:deviceArray});
});
});
module.exports = router;