MCPcopy
hub / github.com/parse-community/parse-server / verifyServerUrl

Method verifyServerUrl

src/ParseServer.ts:532–572  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

530 }
531
532 static async verifyServerUrl() {
533 // perform a health check on the serverURL value
534 if (Parse.serverURL) {
535 const isValidHttpUrl = string => {
536 let url;
537 try {
538 url = new URL(string);
539 } catch {
540 return false;
541 }
542 return url.protocol === 'http:' || url.protocol === 'https:';
543 };
544 const url = `${Parse.serverURL.replace(/\/$/, '')}/health`;
545 if (!isValidHttpUrl(url)) {
546 // eslint-disable-next-line no-console
547 console.warn(
548 `\nWARNING, Unable to connect to '${Parse.serverURL}' as the URL is invalid.` +
549 ` Cloud code and push notifications may be unavailable!\n`
550 );
551 return;
552 }
553 const request = require('./request');
554 const response = await request({ url }).catch(response => response);
555 const json = response.data || null;
556 const retry = response.headers?.['retry-after'];
557 if (retry) {
558 await new Promise(resolve => setTimeout(resolve, retry * 1000));
559 return this.verifyServerUrl();
560 }
561 if (response.status !== 200 || json?.status !== 'ok') {
562 /* eslint-disable no-console */
563 console.warn(
564 `\nWARNING, Unable to connect to '${Parse.serverURL}'.` +
565 ` Cloud code and push notifications may be unavailable!\n`
566 );
567 /* eslint-enable no-console */
568 return;
569 }
570 return true;
571 }
572 }
573}
574
575function addParseCloud() {

Callers 4

serverFunction · 0.80
startAppMethod · 0.80
index.spec.jsFile · 0.80

Calls 2

warnMethod · 0.80
requestFunction · 0.50

Tested by

no test coverage detected