express中间件——https-only

luoyjx · 2015-08-18 09:21 · 1182次阅读

ExpressJS middleware to force applications to accept HTTPS requests only.

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)
收藏

暂无评论

登录后可以进行评论。没有账号?马上注册