forked from zhaohappy/libmedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edp-webserver-config.js
85 lines (82 loc) · 2.4 KB
/
edp-webserver-config.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var fs = require('fs');
var path = require('path');
exports.port = 9000;
exports.protocol = 'http';
exports.tlsOptions = {
key: fs.readFileSync(path.join(__dirname, './test/key.pem')),
cert: fs.readFileSync(path.join(__dirname, './test/cert.pem'))
};
exports.directoryIndexes = true;
exports.documentRoot = __dirname;
exports.getLocations = function () {
return [
{
location: /.html$/,
handler: [
file(),
proxyNoneExists(),
function (context) {
var header = context.header;
header['Cross-Origin-Embedder-Policy'] = 'require-corp';
header['Cross-Origin-Opener-Policy'] = 'same-origin';
header['Cross-Origin-Embedder-Policy-Report-Only'] = 'true';
}
]
},
{
location: /.js$/,
handler: [
file(),
proxyNoneExists(),
function (context) {
var header = context.header;
header['Cross-Origin-Embedder-Policy'] = 'require-corp';
}
]
},
{
location: /.wasm$/,
handler: [
file(),
proxyNoneExists(),
function (context) {
var header = context.header;
header['Content-Type'] = 'application/wasm';
}
]
},
{
location: /^.*$/,
handler: [
file(),
proxyNoneExists(),
function (context) {
var header = context.header;
header['Content-Length'] = context.content.length;
if (context.request.method === 'OPTIONS' || context.request.method === 'HEAD') {
header['X-Content-Length'] = context.content.length;
context.content = null;
}
else {
let range = context.request.rawHeaders.find((value) => {
return value.indexOf('bytes=') >= 0;
});
if (range) {
range = range.replace('bytes=', '');
let start = Math.max(+range.substr(0, range.lastIndexOf('-')), 0);
let endStr = range.substr(range.lastIndexOf('-') + 1);
let end = endStr ? Math.min(+endStr, context.content.length - 1) : context.content.length;
context.content = context.content.slice(start, end + 1);
header['Content-Length'] = context.content.length;
}
}
}
]
}
];
};
exports.injectResource = function ( res ) {
for ( var key in res ) {
global[ key ] = res[ key ];
}
};