chore: add proxy backend (#3126)

* feat(backends): add proxy backend

* feat: add proxy server initial commit

* fix: move from joi to @hapi/joi

* test: add joi validation tests

* feat: proxy server initial implementations

* test: add tests, fix build

* chore: update yarn.lock

* build: fix develop command

* fix(back-proxy): fix bugs

* test(backend-proxy): add cypress tests

* chore: cleanup

* chore: support node 10

* chore: code cleanup

* chore: run cypress on ubuntu 16.04

* test(e2e): fix proxy backend cypress tests

* chore: don't start proxy server on yarn develop
This commit is contained in:
Erez Rokah
2020-01-22 23:47:34 +02:00
committed by Shawn Erquhart
parent cf57da223d
commit 7e8084be87
38 changed files with 2895 additions and 106 deletions

View File

@ -489,18 +489,20 @@ export async function getMediaDisplayURL(
// url loading had an error
url = null;
} else {
if (!displayURLState.get('isFetching')) {
// load display url
dispatch(loadMediaDisplayURL(file));
}
const key = file.id;
url = await waitUntilWithTimeout<string>(dispatch, resolve => ({
const promise = waitUntilWithTimeout<string>(dispatch, resolve => ({
predicate: ({ type, payload }) =>
(type === MEDIA_DISPLAY_URL_SUCCESS || type === MEDIA_DISPLAY_URL_FAILURE) &&
payload.key === key,
run: (_dispatch, _getState, action) => resolve(action.payload.url),
}));
if (!displayURLState.get('isFetching')) {
// load display url
dispatch(loadMediaDisplayURL(file));
}
url = await promise;
}
return url;

View File

@ -22,17 +22,26 @@ export const waitUntilWithTimeout = async <T>(
dispatch(waitUntil(waitActionArgs(resolve)));
});
const timeoutPromise = new Promise<T>((resolve, reject) => {
setTimeout(() => (waitDone ? resolve() : reject(new Error('Wait Action timed out'))), timeout);
const timeoutPromise = new Promise<T | null>(resolve => {
setTimeout(() => {
if (waitDone) {
resolve();
} else {
console.warn('Wait Action timed out');
resolve(null);
}
}, timeout);
});
const result = await Promise.race([
waitPromise.then(result => {
waitDone = true;
return result;
}),
waitPromise
.then(result => {
waitDone = true;
return result;
})
.catch(null),
timeoutPromise,
]).catch(null);
]);
return result;
};