debian-mirror-gitlab/app/assets/javascripts/ide/remote/index.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-03-04 22:38:38 +05:30
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,
});
};