Add a helper for app <-> browser communication.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3908 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-06-19 18:01:21 +00:00
parent d3e9041b15
commit d892c9e734
3 changed files with 82 additions and 2 deletions

View File

@ -225,6 +225,7 @@ async function getProcessBlob(blobId, key, options) {
var id = appObject.files[appSourceName];
var blob = await getBlobOrContent(id);
appSource = utf8Decode(blob);
await process.task.loadFile(['/tfrpc.js', await File.readFile('core/tfrpc.js')]);
await Promise.all(Object.keys(appObject.files).map(async function(f) {
await process.task.loadFile([f, await getBlobOrContent(appObject.files[f])]);
}));
@ -264,6 +265,7 @@ var kStaticFiles = [
{uri: '/style.css', type: 'text/css; charset=UTF-8'},
{uri: '/favicon.png', type: 'image/png'},
{uri: '/client.js', type: 'text/javascript; charset=UTF-8'},
{uri: '/tfrpc.js', type: 'text/javascript; charset=UTF-8', headers: {'Access-Control-Allow-Origin': 'null'}},
{uri: '/robots.txt', type: 'text/plain; charset=UTF-8'},
];
@ -285,7 +287,7 @@ async function staticFileHandler(request, response, blobId, uri) {
var path = kStaticFiles[i].path || uri.substring(1);
var type = kStaticFiles[i].type || guessType(path);
var data = await File.readFile("core/" + path);
response.writeHead(200, {"Content-Type": type, "Content-Length": data.byteLength});
response.writeHead(200, Object.assign({"Content-Type": type, "Content-Length": data.byteLength}, kStaticFiles[i].headers || {}));
response.end(data);
return;
}