node.js https服务器无法呈现应用页面

时间:2016-03-31 20:33:09

标签: node.js https server

我刚刚设置了我的本地https服务器。但是,当我访问我的网站https://localhost:3001或任何类似/home或/ projects的网页时,该网页都无法呈现。有人可以帮忙吗?这是我的代码:

var https = require('https');
var fs = require('fs');
var https_port = 3001;

var options = {
  key: fs.readFileSync('./security/keys/localhost.key'),
  cert: fs.readFileSync('./security/keys/localhost.crt')
};

var a = https.createServer(options, function (req, res) {
  res.writeHead(200);
  console.log('https server works!); //this prints out properly
}).listen(https_port);  

1 个答案:

答案 0 :(得分:0)

您应该使用路由器告诉您的服务器如何处理/home/projects等路径。

var router = require('router');

router.get('/home', function(req, res){
res.send('This is home')
}