-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (31 loc) · 879 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
35
36
37
38
39
40
41
42
var spdy = require('spdy')
var fs = require('fs')
var options = {
key: fs.readFileSync(__dirname + '/keys/server.key'),
cert: fs.readFileSync(__dirname + '/keys/server.crt')
}
var server = spdy.createServer(options, (req, res) => {
res.writeHead(200)
var images = ''
for (i = 0; i <= 500; i++) {
let file = '/images/' + i + '.jpg'
let readfile = fs.readFileSync(__dirname + file)
let stream = res.push(file, {
status: 200,
method: 'GET',
request: {
accept: '*/*'
},
response: {
'content-type': 'image/jpeg'
}
})
stream.on('error', err => {})
images += '<img src="./images/' + i + '.jpg">'
console.log('Pushed: '+file)
stream.end(readfile)
}
res.end('<html><body>'+images+'</body></html>')
})
server.listen(3000)
console.log('Server running at http://127.0.0.1:3000/');