express中间件——https-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)