forked from expressjs/express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (31 loc) · 978 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var http2 = require('http2');
var fs = require('fs');
var path = require('path');
var express = require('../../');
var keys = path.join(__dirname, 'keys');
var app = express();
var style = fs.readFileSync(path.resolve(__dirname, './static/style.css'), 'utf8');
function pushStyle(res) {
res.createPushResponse({
':path': '/style.css',
':status': 200,
'content-type': 'text/css'
}, function(err, newResponse) {
newResponse.setHeader('content-type', 'text/css');
newResponse.end(style);
});
}
app.use(express.static('static', {setHeaders: function(res, file) {
if (file.indexOf('index.html') > -1) {
pushStyle(res);
}
}}));
var server = http2.createSecureServer({
key: fs.readFileSync(path.join(keys, 'test_key.pem')),
cert: fs.readFileSync(path.join(keys, 'test_cert.pem'))
}, app);
/* istanbul ignore next */
if (!module.parent) {
server.listen(3000);
console.log('Express started on port 3000');
}