Skip to content

Commit

Permalink
使用 http2
Browse files Browse the repository at this point in the history
  • Loading branch information
soonxf committed Feb 28, 2023
1 parent c70b4a2 commit 28da985
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Binary file modified express/express-linux
Binary file not shown.
14 changes: 11 additions & 3 deletions express/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const express = require('express');

const spdy = require('spdy');
const rateLimit = require('express-rate-limit');

const helmet = require('helmet');
Expand All @@ -8,7 +8,6 @@ const path = require('path');
const config = require(path.join(process.cwd(), './config'));

const fs = require('fs');
const https = require('https');
const http = require('http');

const { createProxyMiddleware } = require('http-proxy-middleware');
Expand Down Expand Up @@ -75,6 +74,15 @@ httpServer.listen(config.httpPort, () => console.log('http:' + config.httpPort))
httpServer.on('connection', socket => socket.setTimeout(config.setTimeout));

if (key == '' || cert == '') return;
const httpsServer = https.createServer({ key, cert }, app);
const httpsServer = spdy.createServer(
{
key,
cert,
spdy: {
protocols: ['h2', 'spdy/3.1', 'spdy/3', 'spdy/2', 'http/1.1', 'http/1.0'],
},
},
app
);
httpsServer.listen(config.httpsPort, () => console.log('https:' + config.httpsPort));
httpsServer.on('connection', socket => socket.setTimeout(config.setTimeout));
5 changes: 3 additions & 2 deletions express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
"express": "^4.18.2",
"express-rate-limit": "^6.7.0",
"helmet": "^6.0.1",
"http-proxy-middleware": "^2.0.6"
"http-proxy-middleware": "^2.0.6",
"spdy": "^4.0.2"
},
"description": "",
"devDependencies": {
"nodemon": "^2.0.20"
}
}
}

0 comments on commit 28da985

Please sign in to comment.