How to use the @codesandbox/common/lib/utils/url-generator.protocolAndHost function in @codesandbox/common

To help you get started, we’ve selected a few @codesandbox/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codesandbox / codesandbox-client / packages / node-services / src / child_process.ts View on Github external
sentBroadcastsForPath.shift();
  }
  sentBroadcastsForPath.push(data.$id);
  if (
    // @ts-ignore This check is for the subworker polyfill, if it has an id it's polyfilled by subworkers and indeed a worker
    target.id ||
    target.constructor.name === 'Worker' ||
    // @ts-ignore Unknown to TS
    (typeof DedicatedWorkerGlobalScope !== 'undefined' &&
      // @ts-ignore Unknown to TS
      target instanceof DedicatedWorkerGlobalScope)
  ) {
    // @ts-ignore
    target.postMessage(data);
  } else {
    (target as Window).postMessage(data, protocolAndHost());
  }

  sentBroadcasts.set(path, sentBroadcastsForPath);
}
github codesandbox / codesandbox-client / packages / app / src / app / pages / ZeitAuth / index.js View on Github external
super(props);

    // eslint-disable-next-line no-unused-vars
    const [_, code] = document.location.search.match(/\?code=(.*)/);

    if (code) {
      if (window.opener) {
        if (window.opener.location.origin === window.location.origin) {
          window.opener.postMessage(
            {
              type: 'signin',
              data: {
                code,
              },
            },
            protocolAndHost()
          );
        }
        return;
      }
      this.state = {
        redirect: '/',
      };
      return;
    }

    this.state = {
      error: 'no message received',
    };
  }
github codesandbox / codesandbox-client / packages / sandbox-hooks / preview-secret.js View on Github external
function getProtocolAndHostWithSSE() {
  if (process.env.CODESANDBOX_HOST) {
    return protocolAndHost();
  }

  if (document.location.host.endsWith('.stream')) {
    return 'https://codesandbox.stream';
  }

  return 'https://codesandbox.io';
}
github codesandbox / codesandbox-client / packages / app / src / app / pages / SignInAuth / index.js View on Github external
super(props);

    if (props.match.params.jwt) {
      if (window.opener) {
        this.state = {
          jwt: props.match.params.jwt,
        };
        if (window.opener.location.origin === window.location.origin) {
          window.opener.postMessage(
            {
              type: 'signin',
              data: {
                jwt: props.match.params.jwt,
              },
            },
            protocolAndHost()
          );
        }
        return;
      }
      this.state = {
        redirect: '/',
      };
      return;
    }

    this.state = {
      error: 'no message received',
    };
  }
github codesandbox / codesandbox-client / packages / app / src / app / store / providers / FSSync.ts View on Github external
function sendTypes() {
  global.postMessage(
    {
      $broadcast: true,
      $type: 'typings-sync',
      $data: types,
    },
    protocolAndHost()
  );
}
github codesandbox / codesandbox-client / packages / node-services / src / net.ts View on Github external
write(buffer: Buffer) {
    if (this.destroyed) {
      return;
    }

    const message = {
      $type: SOCKET_IDENTIFIER,
      $channel: this.channel,
      data: JSON.stringify(buffer),
    };

    if (this.isWorker) {
      ((this.target as unknown) as Worker).postMessage(message);
    } else {
      (this.target as Window).postMessage(message, protocolAndHost());
    }
  }
}
github codesandbox / codesandbox-client / packages / app / src / app / overmind / effects / vscode / SandboxFsSync / index.ts View on Github external
private send(type: string, data: any, id?: string) {
    global.postMessage(
      {
        $broadcast: true,
        $fs_ids: typeof id === 'undefined' ? this.workerIds : [id],
        $type: type,
        $data: data,
      },
      protocolAndHost()
    );
  }
github codesandbox / codesandbox-client / packages / app / src / app / pages / common / Modals / ShareModal / getCode.ts View on Github external
export const getEditorUrl = (sandbox, mainModule, state) =>
  protocolAndHost() +
  sandboxUrl(sandbox) +
  getOptionsUrl(sandbox, mainModule, state);