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)
A
这一层我是在 nginx 上面做的
L
引用 alsotang这一层我是在 nginx 上面做的
@alsotang 用ip好像还是可以非https,不过一般人也不会用ip去访问。。。
A
引用 luoyjx@alsotang 用ip好像还是可以非https,不过一般人也不会用ip去访问。。。
@luoyjx 不经过 80 端口的话就不经过 nginx,不是 ip 的原因
L
引用 alsotang@luoyjx 不经过 80 端口的话就不经过 nginx,不是 ip 的原因
@alsotang 直接访问8080的话。。。
参与回复
登录后即可参与回复。登录