Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js TLS“;TypeError:无法读取属性';指数';“未定义”的定义;_Node.js_Ssl_Express - Fatal编程技术网

Node.js TLS“;TypeError:无法读取属性';指数';“未定义”的定义;

Node.js TLS“;TypeError:无法读取属性';指数';“未定义”的定义;,node.js,ssl,express,Node.js,Ssl,Express,我使用nodejs5.9.0和express。在我的代码中,我通过以下方式创建服务器: var app = express(); var tls = require('tls'); var fs = require('fs'); var options = { key: fs.readFileSync('key.pem'), cert: fs.readFileSync('cert.pem') }; tls.createServer(options, app).listen(3000);

我使用nodejs5.9.0和express。在我的代码中,我通过以下方式创建服务器:

var app = express();

var tls = require('tls');
var fs = require('fs');
var options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};
tls.createServer(options, app).listen(3000);

var http = require('http');
http.createServer(app).listen(80);
HTTP工作正常。但当我尝试访问时,它抛出以下异常:

C:\src\nodejs\videos\node_modules\express\lib\router\index.js:140
  var search = 1 + req.url.indexOf('?');
                          ^

TypeError: Cannot read property 'indexOf' of undefined
    at Function.handle (C:\src\nodejs\videos\node_modules\express\lib\router\index.js:140:27)
    at EventEmitter.handle (C:\src\nodejs\videos\node_modules\express\lib\application.js:173:10)
    at Server.app (C:\src\nodejs\videos\node_modules\express\lib\express.js:38:9)
    at emitOne (events.js:90:13)
    at Server.emit (events.js:182:7)
    at TLSSocket.<anonymous> (_tls_wrap.js:817:14)
    at emitNone (events.js:80:13)
    at TLSSocket.emit (events.js:179:7)
    at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:593:8)
    at TLSSocket.onhandshakedone (_tls_wrap.js:65:8)
 Program node bin/www exited with code 1
C:\src\nodejs\videos\node\u modules\express\lib\router\index.js:140
var search=1+req.url.indexOf(“?”);
^
TypeError:无法读取未定义的属性“indexOf”
位于Function.handle(C:\src\nodejs\videos\node\u modules\express\lib\router\index.js:140:27)
位于EventEmitter.handle(C:\src\nodejs\videos\node\u modules\express\lib\application.js:173:10)
在Server.app(C:\src\nodejs\videos\node\u modules\express\lib\express.js:38:9)
在emitOne(events.js:90:13)
在Server.emit(events.js:182:7)
在TLSSocket。(_tls_wrap.js:817:14)
在emitNone(events.js:80:13)
在TLSSocket.emit(events.js:179:7)
在TLSSocket.\u init.ssl.onclienthlo.ssl.oncertcb.TLSSocket.\u finishini(\u tls\u wrap.js:593:8)
在TLSSocket.onhandshakedone(_tls_wrap.js:65:8)
程序节点bin/www已退出,代码为1

我使用nodejs TLS和express的方式正确吗?

您需要在express应用程序中使用
https
,而不是
TLS
,因为
TLS
基本上只是一个普通的TCP连接(由TLS保护):


您需要在Express应用程序中使用
https
,而不是
tls
,因为
tls
基本上只是一个普通的TCP连接(受tls保护):


谢谢有趣的。。。这基本上就是我最初使用的代码,但是浏览器给我带来了安全异常。好。。。在过去的30分钟里,我确实将nodejs从5.5.0升级到了5.9.0。不确定这是否解决了问题。谢谢!有趣的。。。这基本上就是我最初使用的代码,但是浏览器给我带来了安全异常。好。。。在过去的30分钟里,我确实将nodejs从5.5.0升级到了5.9.0。不确定这是否解决了问题。
var app = express();

var fs = require('fs');
var http = require('http');
var https = require('https');

var options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

https.createServer(options, app).listen(3000);
http.createServer(app).listen(80);