nodejs表示要停留在http上的力量

编程入门 行业动态 更新时间:2024-10-09 00:44:39

nodejs表示要<a href=https://www.elefans.com/category/jswz/34/1770515.html style=停留在http上的力量"/>

nodejs表示要停留在http上的力量

正在使用NodeJs应用程序,并且我想欺骗浏览器,以便保留http,最新版本的浏览器,并将其重定向到https。

我知道不建议这样做,但只建议用于PoC,因此没有不安全的通信不会成为主要问题。

var port = 80;

server.listen(port, function () {
    console.log('webapp: listening at port %d', port);
});

    // Routing
    const currentDirectory = path.join(__dirname, '../', 'webapp');
    app
        .get('/', applyTemplate('index.html'))
        .get('/index.html', applyTemplate('index.html'))
        .use(express.static(currentDirectory))

我可以欺骗浏览器吗?处理https连接并将其重定向到http而不创建ssl证书。

回答如下:

您需要使用openssl创建自签名证书,然后使用它。

我附上一个示例,您可以在=> https://timonweb/posts/running-expressjs-server-over-https/中找到

openssl req -nodes -new -x509 -keyout server.key -out server.cert
var express = require('express')
var fs = require('fs')
var https = require('https')
var app = express()

app.get('/', function (req, res) {
  res.send('hello world')
})

https.createServer({
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.cert')
}, app)
.listen(3000, function () {
  console.log('Example app listening on port 3000! Go to https://localhost:3000/')
})

更多推荐

nodejs表示要停留在http上的力量

本文发布于:2024-05-07 20:22:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1757091.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:停留在   力量   nodejs   http

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!