-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (30 loc) · 1.09 KB
/
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
/*!
* Teo.JS streamer extension
* @author Andrew Teologov <[email protected]>
* @date 3/30/16
*/
"use strict";
const mime = require("mime"),
streamer = require("./lib/streamer");
module.exports = {
extension(appContext, config = {}) { // streamer extension should be as a separate argument not with app's config(!)
let config = Object.assign({
// download file instead of streaming
forceDownload: false,
// max age for Cache-Control
maxAge: 3600,
cors: false,
// (limit) server bandwidth (bytes/second). See https://www.npmjs.com/package/throttle
throttle: false
}, config);
appContext.middleware(function* (next) {
if (this.req.headers.range) {
let contentType = mime.lookup(this.extension || this.req.headers.accept || "html");
streamer(this.req, this.res, config, path.normalize(path.join(this.config.get("appDir"), this.pathname)), contentType);
}
else {
yield next;
}
});
}
};