簡體   English   中英

nodejs快遞力留在http

[英]nodejs express force to stay on 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 和 HTTP 之間發送密碼或敏感數據。 我可以問你為什么要跳過這些檢查嗎? 大多數時候,一個做得好的測試套件足以以正確的方式處理這些情況,並獲得瀏覽器的正確響應。

我附上了一個示例,您可以在 =>https://timonweb.com/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/')
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM