forked from cory/tildefriends
Integrate speedscope. Just visit /scope.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3695 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
29
core/core.js
29
core/core.js
@ -312,6 +312,30 @@ async function staticFileHandler(request, response, blobId, uri) {
|
||||
response.end("File not found");
|
||||
}
|
||||
|
||||
async function speedScopeHandler(request, response, uri) {
|
||||
var filename = uri || 'index.html';
|
||||
if (filename.indexOf('..') != -1) {
|
||||
response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Content-Length": "File not found".length});
|
||||
response.end("File not found");
|
||||
return;
|
||||
}
|
||||
|
||||
const types = {
|
||||
'json': 'text/json',
|
||||
'js': 'text/javascript',
|
||||
'html': 'text/html',
|
||||
'css': 'text/css',
|
||||
};
|
||||
try {
|
||||
var data = await File.readFile("deps/speedscope/" + filename);
|
||||
response.writeHead(200, {"Content-Type": types[filename.split('.').pop()] || 'text/plain', "Content-Length": data.byteLength});
|
||||
response.end(data);
|
||||
} catch {
|
||||
response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Content-Length": "File not found".length});
|
||||
response.end("File not found");
|
||||
}
|
||||
}
|
||||
|
||||
function sendData(response, data) {
|
||||
if (data) {
|
||||
if (startsWithBytes(data, [0xff, 0xd8, 0xff, 0xdb]) ||
|
||||
@ -459,6 +483,11 @@ loadSettings().then(function() {
|
||||
return blobHandler(request, response, match[1], match[2]);
|
||||
} else if (match = /^\/static(\/.*)/.exec(request.uri)) {
|
||||
return staticFileHandler(request, response, null, match[1]);
|
||||
} else if (match = /^\/scope$/.exec(request.uri)) {
|
||||
response.writeHead(303, {"Location": 'http://' + request.headers.host + '/speedscope/#profileURL=http://' + request.headers.host + '/trace', "Content-Length": "0"});
|
||||
return response.end(data);
|
||||
} else if (match = /^\/speedscope\/([\.\w-]*)$/.exec(request.uri)) {
|
||||
return speedScopeHandler(request, response, match[1]);
|
||||
} else if (match = /^(.*)(\/save)$/.exec(request.uri)) {
|
||||
return blobHandler(request, response, match[1], match[2]);
|
||||
} else if (match = /^\/trace$/.exec(request.uri)) {
|
||||
|
Reference in New Issue
Block a user