nodejs https sendfile错误

时间:2016-02-13 12:01:46

标签: node.js https

我能够使用带有http的sendfile,但似乎无法在https上下文中使用它。我是否需要嵌套sendfile命令?

错误

/home/ubuntu/proto.js:20 response.sendFile('index.html'); ^ TypeError: Cannot call method 'sendFile' of undefined

Nodejs代码

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var fs = require('fs');
var https = require('https');
var options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem'),
  rejectUnauthorized: false
};
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

https.createServer(options, function (req, res) {
  res.writeHead(200);
  //https.sendFile('/home/ubuntu/index.html');
  res.end("hello world\n");
}).listen(443);

https.get('/', function(request, response){
  response.sendFile('index.html');
});

0 个答案:

没有答案