在某些情况下,我需要在我的网站上使用 SSL,
我已按照自述文件中的示例进行操作
require('compound').createServer({
key: fs.readFileSync('/tmp/tls.key').toString(),
cert: fs.readFileSync('/tmp/tls.cert').toString()
});
我的 server.js 是
#!/usr/bin/env node
var fs = require('fs');
/**
* Server module exports method returning new instance of app.
*
* @param {Object} params - compound/express webserver initialization params.
* @returns CompoundJS powered express webserver
*/
var app = module.exports = function getServerInstance(params) {
params = params || {};
// specify current dir as default root of server
params.root = params.root || __dirname;
params["key"] = fs.readFileSync('/tmp/tls.key').toString();
params["cert"] = fs.readFileSync('/tmp/tls.cert').toString();
return require('compound').createServer(params);
};
if (!module.parent) {
var port = process.env.PORT || 3000;
var host = process.env.HOST || '0.0.0.0';
var server = app();
server.listen(port, host, function () {
console.log(
'Compound server listening on %s:%d within %s environment',
host, port, server.set('env')
);
});
}
现在的问题是我无法获得http,只有https。如果我只是将我的证书和密钥放在配置文件夹中并拥有
**var app = module.exports = function getServerInstance(params) {
params = params || {};
// specify current dir as default root of server
params.root = params.root || __dirname;
return require('compound').createServer(params);
};**
然后我得到一些错误
config/tls.cert:1
tion (exports, require, module, __filename, __dirname) { -----BEGIN CERTIFICAT
^^^^^^^^^^^
SyntaxError: Unexpected identifier
at Module._compile (module.js:439:25)
让 Compoundjs 支持 https 和 http 路由的最快和最简单的方法是什么,我是否需要有两台服务器(就像你经常使用直接快递一样)?