Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « remote « ide « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb8db20c0c133c0a7f92ec3f7572c9a8b3d248e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { startRemote } from '@gitlab/web-ide';
import { getBaseConfig, setupRootElement } from '~/ide/lib/gitlab_web_ide';
import { isSameOriginUrl, joinPaths } from '~/lib/utils/url_utility';

/**
 * @param {Element} rootEl
 */
export const mountRemoteIDE = async (el) => {
  const {
    remoteHost: remoteAuthority,
    remotePath: hostPath,
    cspNonce,
    connectionToken,
    returnUrl,
  } = el.dataset;

  const rootEl = setupRootElement(el);

  const visitReturnUrl = () => {
    // security: Only change `href` if of the same origin as current page
    if (returnUrl && isSameOriginUrl(returnUrl)) {
      window.location.href = returnUrl;
    } else {
      window.location.reload();
    }
  };

  startRemote(rootEl, {
    ...getBaseConfig(),
    nonce: cspNonce,
    connectionToken,
    // remoteAuthority must start with "/"
    remoteAuthority: joinPaths('/', remoteAuthority),
    // hostPath must start with "/"
    hostPath: joinPaths('/', hostPath),
    // TODO Handle error better
    handleError: visitReturnUrl,
    handleClose: visitReturnUrl,
  });
};