问题描述
在我的app.js中,我放了以下内容:
var app = express();
//查看引擎设置
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);
加载
在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();
//查看引擎设置
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并转发到错误处理程序
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();
/ *显示从2011年起每个设备ID测试的数量,使用d3 * /
/ *查询将首先选择所有批记录及其最早的测试日期(这是 P'插入物料量);
然后使用{lotid,lotstartdate}检索所有第一个插入批记录,然后每个设备添加批量;
然后返回顶部接种材料数量的第20个设备ID;
* /
router.get('/',function(req,res){
query.connectionParameters = config.reportConnStr; //连接到localhost
var deviceArray = new Array();
var sqlstr =sdfsfdfsdsfds;
query(sqlstr,function(err,rows,result){
assert.equal(rows,result.rows);
for(var i = 0; 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。事实证明,它可能不是中间件的顺序。
返回函数(请求,响应,下一个){
if(!request.connection.id){
request.connection.id = utils.uuidv4();
}
var auth_headers = request.headers.authorization;
var user = request.connection.ntlm;
....
}
在这里,我的request.connection。 ntlm为null。
这里可能是什么原因?是关于浏览器设置还是我的网络设置?
我正在公司网络上运行,我在一个网络域。
更新:
在app.js中更改为: p>
app.use(ntlm());
app.use('/',search);
app.use('/',TT);
app.use('/',KYEC_stat);
app.use('/',ftc);
app.use('/',volPerDevice);
app.use('/',routes);
并在topVolPerDevice文件的路由器中添加/ vol:
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();
/ *显示从2011年起每个设备ID测试的数量,使用d3 * /
/ *查询将首先选择所有批记录及其最早的测试日期(这是 P'插入物料量);
然后使用{lotid,lotstartdate}检索所有第一个插入批记录,然后每个设备添加批量;
然后返回顶部接种材料数量的第20个设备ID;
* /
router.get('/ vol',function(req,res){
query.connectionParameters = config.reportConnStr; //连接到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;
I am trying to use express-ntlm to get windows user name without authentication.
in my app.js, i put the following:
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);
This gives me a 401 error in node.js when loading http://localhost:3000/searchIn chrome console: Failed to load resource: Failed to load resource: net::ERR_UNEXPECTED
what is the correct sequence of routing here?thanks.
========= modified to ==============
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;
===== update 2/25/2015 =============
I am re-visiting the problem this week, and I reached a little bit further.I tried to put down a few debug statements in express-ntlm.js and also installed firebug in firefox. It turns out that it is probably not about the sequence of middleware.
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;
....
}
over here, my request.connection.ntlm is null.
What could be the reason here? is it about browser settings or my network settings?
I am running this over company network, and I am on a network domain.
UPDATE:
Change to this in the app.js:
app.use(ntlm());
app.use('/', search);
app.use('/', TT);
app.use('/', KYEC_stat);
app.use('/', ftc);
app.use('/', volPerDevice);
app.use('/', routes);
And add '/vol' in the router in the topVolPerDevice file:
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;
这篇关于如何使用express-ntlm获取Windows用户名,而不使用NODE.js进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!