1.安装 npm i browser-sync
2. 再angular.json里配置文章来源:https://www.toymoban.com/news/detail-656281.html
"serve-ssr": {
"builder": "@nguniversal/builders:ssr-dev-server",
"options": {
"ssl": true,
"sslCert": "./node_modules/browser-sync/certs/server.crt",
"sslKey": "./node_modules/browser-sync/certs/server.key"
},
3.server.ts 修改function run()文章来源地址https://www.toymoban.com/news/detail-656281.html
function run(): void {
const port = process.env['PORT'] || 4200;
// https certificates
const privateKey = fs.readFileSync('./node_modules/browser-sync/certs/server.key');
const certificate = fs.readFileSync('./node_modules/browser-sync/certs/server.crt');
// Start up the Node server
// Start up the Node server
let server;
if (process.argv && process.argv.includes('--ssl')) {
server = https.createServer({ key: privateKey, cert: certificate }, app());
} else {
server = app();
}
server.listen(port, () => {
console.log(`Node Express server listening on https://localhost:${port}`);
});
}
到了这里,关于SSR使用HTTPS的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!