express中间件——https-only
发布于 9 年前 作者 luoyjx 3995 次浏览 最后一次编辑是 8 年前 来自 分享

https-only,是一个express的中间件,使应用只能接受https请求。

安装

npm install https-only

使用

var httpsOnly = require('https-only')
var express = require('express')
var app = express()
 
// Enable https-only 
app.use(httpsOnly())
 
// Any routes beneath the https-only middleware will need to be 
// accessed via HTTPS 
app.use('/', function(req, res) {
  res.send('hello world')
})
 
// Error handler 
app.use(function(err, req, res, next) {
  res.status(err.status)
  res.send({message: err.message})
})
 
app.listen(3000)
4 回复

这一层我是在 nginx 上面做的

@alsotang 用ip好像还是可以非https,不过一般人也不会用ip去访问。。。

@luoyjx 不经过 80 端口的话就不经过 nginx,不是 ip 的原因

@alsotang 直接访问8080的话。。。

回到顶部