【发布时间】:2019-07-22 08:58:57
【问题描述】:
我已经通过这样做将我的nodejs 服务器转换为使用https
const https = require('https');
const privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
const certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
const app = express();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, X-access-token');
next();
});
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(port)
.on('error', error => {
logger.error(error);
})
.on('listening', () => {
logger.info(`Express listening on ${port}`);
});
现在,当我使用 jquery 提供 html 文件时,API 调用工作正常,当我使用 postman 时,我需要从 settings --> general 禁用 ssl certificate validation 并且它有效,现在我正在尝试部署 angular 6 应用程序在我的localhost 上,而服务器在某个 IP 的天蓝色上,但我收到ERR_CONNECTION_REFUSED 错误。我想如果邮递员通过删除验证选项来工作,我需要在角度代码中为此做类似的事情吗?
目前 API 位于 https://137.xxx.xx.xx:8000/api/v0/......
【问题讨论】:
标签: node.js angularjs angular express ssl