mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
Minify: Asyncify requestURI()
This commit is contained in:
parent
a952df2cf5
commit
1ec29e0d45
1 changed files with 39 additions and 39 deletions
|
@ -50,13 +50,13 @@ const LIBRARY_WHITELIST = [
|
|||
|
||||
// What follows is a terrible hack to avoid loop-back within the server.
|
||||
// TODO: Serve files from another service, or directly from the file system.
|
||||
const requestURI = (url, method, headers, callback) => {
|
||||
const parsedURL = urlutil.parse(url);
|
||||
|
||||
let status = 500;
|
||||
const requestURI = async (url, method, headers) => {
|
||||
var headers = {};
|
||||
const content = [];
|
||||
|
||||
return await new Promise((resolve) => {
|
||||
const parsedURL = urlutil.parse(url);
|
||||
let status = 500;
|
||||
const content = [];
|
||||
const mockRequest = {
|
||||
url,
|
||||
method,
|
||||
|
@ -83,11 +83,11 @@ const requestURI = (url, method, headers, callback) => {
|
|||
},
|
||||
end: (_content) => {
|
||||
_content && content.push(_content);
|
||||
callback(status, headers, content.join(''));
|
||||
resolve([status, headers, content.join('')]);
|
||||
},
|
||||
};
|
||||
|
||||
minify(mockRequest, mockResponse);
|
||||
});
|
||||
};
|
||||
|
||||
const requestURIs = (locations, method, headers, callback) => {
|
||||
|
@ -101,15 +101,15 @@ const requestURIs = (locations, method, headers, callback) => {
|
|||
callback(statuss, headerss, contentss);
|
||||
};
|
||||
|
||||
const respondFor = (i) => (status, headers, content) => {
|
||||
responses[i] = [status, headers, content];
|
||||
const respondFor = (i) => (response) => {
|
||||
responses[i] = response;
|
||||
if (--pendingRequests === 0) {
|
||||
completed();
|
||||
}
|
||||
};
|
||||
|
||||
for (let i = 0, ii = locations.length; i < ii; i++) {
|
||||
requestURI(locations[i], method, headers, respondFor(i));
|
||||
requestURI(locations[i], method, headers).then(respondFor(i));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -233,7 +233,7 @@ const getAceFile = (callback) => {
|
|||
let resourceURI = baseURI + path.normalize(path.join('/static/', filename));
|
||||
resourceURI = resourceURI.replace(/\\/g, '/'); // Windows (safe generally?)
|
||||
|
||||
requestURI(resourceURI, 'GET', {}, (status, headers, body) => {
|
||||
requestURI(resourceURI, 'GET', {}).then(([status, headers, body]) => {
|
||||
const error = !(status === 200 || status === 404);
|
||||
if (!error) {
|
||||
data += `Ace2Editor.EMBEDED[${JSON.stringify(filename)}] = ${
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue