最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 9浏览 0评论

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上的力量

正在使用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/')
})

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论