mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
Minify: Refactor requestURI()
for readability
This commit is contained in:
parent
3a8d66ba6a
commit
aaacbd3a7a
1 changed files with 29 additions and 25 deletions
|
@ -48,7 +48,7 @@ const LIBRARY_WHITELIST = [
|
||||||
|
|
||||||
// What follows is a terrible hack to avoid loop-back within the server.
|
// 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.
|
// TODO: Serve files from another service, or directly from the file system.
|
||||||
const requestURI = async (url, method, headers) => await new Promise((resolve, reject) => {
|
const requestURI = async (url, method, headers) => {
|
||||||
const parsedUrl = new URL(url);
|
const parsedUrl = new URL(url);
|
||||||
let status = 500;
|
let status = 500;
|
||||||
const content = [];
|
const content = [];
|
||||||
|
@ -58,7 +58,9 @@ const requestURI = async (url, method, headers) => await new Promise((resolve, r
|
||||||
params: {filename: (parsedUrl.pathname + parsedUrl.search).replace(/^\/static\//, '')},
|
params: {filename: (parsedUrl.pathname + parsedUrl.search).replace(/^\/static\//, '')},
|
||||||
headers,
|
headers,
|
||||||
};
|
};
|
||||||
const mockResponse = {
|
let mockResponse;
|
||||||
|
const p = new Promise((resolve) => {
|
||||||
|
mockResponse = {
|
||||||
writeHead: (_status, _headers) => {
|
writeHead: (_status, _headers) => {
|
||||||
status = _status;
|
status = _status;
|
||||||
for (const header in _headers) {
|
for (const header in _headers) {
|
||||||
|
@ -81,8 +83,10 @@ const requestURI = async (url, method, headers) => await new Promise((resolve, r
|
||||||
resolve([status, headers, content.join('')]);
|
resolve([status, headers, content.join('')]);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
minify(mockRequest, mockResponse).catch(reject);
|
});
|
||||||
});
|
await minify(mockRequest, mockResponse);
|
||||||
|
return await p;
|
||||||
|
};
|
||||||
|
|
||||||
const requestURIs = (locations, method, headers, callback) => {
|
const requestURIs = (locations, method, headers, callback) => {
|
||||||
Promise.all(locations.map((loc) => requestURI(loc, method, headers))).then((responses) => {
|
Promise.all(locations.map((loc) => requestURI(loc, method, headers))).then((responses) => {
|
||||||
|
|
Loading…
Reference in a new issue