Skip to content

Commit 288627c

Browse files
committed
serve mime types
1 parent ee77282 commit 288627c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/streamer/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import path from 'path';
44
import portfinder from 'portfinder';
55
import fs from 'mz/fs';
66
import fetch from 'node-fetch';
7+
import mime from 'mime';
8+
import Url from 'url';
79

810
class Streamer {
911
constructor(repo, port) {
@@ -25,7 +27,13 @@ class Streamer {
2527
this.resolveEpub(`${req.params.book}.epub`, req.params.url)
2628
.then(this.open)
2729
.then((zip) => this.get(zip, req.params.asset))
28-
.then((stream) => stream.pipe(res))
30+
.then((stream) => {
31+
let asset = req.params.asset;
32+
let path = Url.parse(asset).pathname || '';
33+
let mimeType = mime.lookup(path);
34+
res.contentType(mimeType);
35+
stream.pipe(res)
36+
})
2937
.catch((err) => {
3038
console.error(err);
3139
res.statusMessage = 'File not found';

0 commit comments

Comments
 (0)