Commit bb53f55d authored by Miguel Rincon's avatar Miguel Rincon

Use gon.gitlab_url to create absolute path

parent ef3b8cd5
...@@ -17,20 +17,18 @@ export class CiSchemaExtension extends EditorLiteExtension { ...@@ -17,20 +17,18 @@ export class CiSchemaExtension extends EditorLiteExtension {
* @param {String?} opts.ref - Current ref. Defaults to master * @param {String?} opts.ref - Current ref. Defaults to master
*/ */
registerCiSchema({ projectNamespace, projectPath, ref = 'master' } = {}) { registerCiSchema({ projectNamespace, projectPath, ref = 'master' } = {}) {
const ciSchemaUri = Api.buildUrl(Api.projectFileSchemaPath) const ciSchemaPath = Api.buildUrl(Api.projectFileSchemaPath)
.replace(':namespace_path', projectNamespace) .replace(':namespace_path', projectNamespace)
.replace(':project_path', projectPath) .replace(':project_path', projectPath)
.replace(':ref', ref) .replace(':ref', ref)
.replace(':filename', EXTENSION_CI_SCHEMA_FILE_NAME_MATCH); .replace(':filename', EXTENSION_CI_SCHEMA_FILE_NAME_MATCH);
const modelFileName = this.getModel().uri.path.split('/').pop();
// In order for workers loaded from `data://` as the // In order for workers loaded from `data://` as the
// ones loaded by monaco, we use absolute URLs to fetch // ones loaded by monaco editor, we use absolute URLs
// schema files, hence the `location.origin` reference. // to fetch schema files, hence the `gon.gitlab_url`
// This prevents error: // reference. This prevents error:
// "Failed to execute 'fetch' on 'WorkerGlobalScope'" // "Failed to execute 'fetch' on 'WorkerGlobalScope'"
// eslint-disable-next-line no-restricted-globals const absoluteSchemaUrl = gon.gitlab_url + ciSchemaPath;
const absoluteSchemaUrl = location.origin + ciSchemaUri; const modelFileName = this.getModel().uri.path.split('/').pop();
registerSchema({ registerSchema({
uri: absoluteSchemaUrl, uri: absoluteSchemaUrl,
......
...@@ -10,6 +10,7 @@ describe('~/editor/editor_ci_config_ext', () => { ...@@ -10,6 +10,7 @@ describe('~/editor/editor_ci_config_ext', () => {
let editor; let editor;
let instance; let instance;
let editorEl; let editorEl;
let originalGitlabUrl;
const createMockEditor = ({ blobPath = defaultBlobPath } = {}) => { const createMockEditor = ({ blobPath = defaultBlobPath } = {}) => {
setFixtures('<div id="editor"></div>'); setFixtures('<div id="editor"></div>');
...@@ -23,6 +24,15 @@ describe('~/editor/editor_ci_config_ext', () => { ...@@ -23,6 +24,15 @@ describe('~/editor/editor_ci_config_ext', () => {
instance.use(new CiSchemaExtension()); instance.use(new CiSchemaExtension());
}; };
beforeAll(() => {
originalGitlabUrl = gon.gitlab_url;
gon.gitlab_url = TEST_HOST;
});
afterAll(() => {
gon.gitlab_url = originalGitlabUrl;
});
beforeEach(() => { beforeEach(() => {
createMockEditor(); createMockEditor();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment