跳到主要内容
CNode

express中间件——https-only

分享
Lluoyjx发布于 11 年前最后回复 11 年前
448320

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)

L
luoyjx#411 年前
A
alsotang#311 年前
引用 luoyjx@alsotang 用ip好像还是可以非https,不过一般人也不会用ip去访问。。。

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

L
luoyjx#211 年前
引用 alsotang这一层我是在 nginx 上面做的

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

A
alsotang#111 年前

这一层我是在 nginx 上面做的

参与回复

登录后即可参与回复。登录