【发布时间】:2016-06-29 23:20:52
【问题描述】:
这是我第一次部署 ssl。我有在 localhost:4000 运行的 express 节点 js 模块。我已经生成了自签名证书并安装在服务器中并且它正在工作。现在,我的 angularjs 前端在 localhost:3000 运行(我使用 http-server 运行 angular 代码)。
为了让我的观点更清楚,这是服务器端的代码:-
// Import node js modules
var https = require('https')
var fs = require('fs')
var express = require('express')
// Load App configuration
var config = require('./config/config')
// Database Integration Here(mongodb)
// Initialize the express app
var app = express()
// App express Configuration
// parse application/json
app.use(bodyParser.json())
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true}))
app.use(cors())
app.set('serverHost', config.server.host)
app.set('serverPort', config.server.port)
app.set('serverUrl', config.server.url)
// Initializing various app modules
// Initialize the components
//Initialize the route(controller)
// Start the app with a given port no and mode
var env = process.env.NODE_ENV || 'development'
var httpsOptions = {
key: fs.readFileSync(__dirname + '/cert/server.key'),
cert: fs.readFileSync(__dirname + '/cert/server.crt')
}
https.createServer(httpsOptions, app).listen(app.get('serverPort'), function () {
// Server and mode info
console.log('The homerungurus backend running on server: '
+ app.get('serverHost')
+ ' and the port is: '
+ app.get('serverPort'))
console.log("The mode is: " + env)
})
如您所见,我已在服务器中安装了证书。 我不需要 http-proxy,因为我会在标准端口 443 上部署 Angular 网络服务器。
我无法理解一些事情:-
- 如何在我的 Angular 模块中启用和设置 ssl 证书,以便 express 和 angular 可以通过 ssl 进行通信。
- 如何在浏览器中显示我的后端 express 节点的证书?
我希望我的观点更清楚了。
任何帮助表示赞赏?
【问题讨论】:
-
请提供更多代码以便我们为您提供帮助:MCVE
-
@AGE 我添加了更多内容。希望这就足够了。
标签: javascript angularjs node.js ssl express