expressjs http不适用于spdy

时间:2017-02-10 13:00:57

标签: node.js express http2 spdy

我想将所有不安全的http流量重定向到安全的spdy服务器。如果我要用https协议打开页面,我得到了服务器的响应,但是当我试图用http访问它时,浏览器只是继续旋转而我根本没有响应。

const express          = require('express')
const https            = require('spdy')
const http             = require('http')
const ECT              = require('ect')
const upload           = multer({ dest: __dirname + '../public/uploads/'})
const cookieParser     = require('cookie-parser')
const bodyParser       = require('body-parser')
const session          = require('express-session')
const passport         = require('passport')
const redis            = require('redis')
const RedisStore       = require('connect-redis')(session)
const fs               = require('fs')
const url              = require('url')
const expressValidator = require('express-validator')
const compression      = require('compression')
const _                = require('lodash')
const env              = process.env.NODE_ENV || 'production'; // development or production => changes config and secrets settings
const secrets          = require('./config/secrets')[env];
const azureconf          = require('./config/azure');
const app              = express()
const ectRenderer      = ECT({ watch: true, root: __dirname + '/views', ext : '.ect', gzip: true });
const client           = redis.createClient()
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(expressValidator());
app.set('view engine', 'ect');
app.engine('ect', ectRenderer.render);
app.use(compression())
app.use(express.static(__dirname + '/public', { maxAge: 2419200 }));
app.use(session({
      store: new RedisStore({
          host:'127.0.0.1',
          port: 6379,
          client: client
        }),
    secret:'mostsecuresecretintheworld',
    saveUninitialized: false,
    resave: true,
    cookie: {
        path: '/',
        httpOnly: false,
        secure: true,
        maxAge: null
      },
    domain: 'mydomain.com'
}));
const certOptions = {   key: fs.readFileSync('certs/server/my-server.key.pem'), cert: fs.readFileSync('certs/ServerCertificate.crt') };
var unsecureServer = http.createServer(function (req, res) {
  res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
  res.end();
})
var secureServer = https.createServer(certOptions, app);
secureServer.listen(443);
unsecureServer.listen(80)

我将不胜感激,谢谢。

1 个答案:

答案 0 :(得分:0)

  

expressjs http不适用于spdy

因为HTTP不是SPDY。这些是完全不同的协议。

请参阅:

支持SPDY的模块。