Skip to content

Feature/relative url #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist
out
.DS_Store
release
.cache
.vscode
.cache
14 changes: 9 additions & 5 deletions packages/ide/src/fill/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
},
set: (value: string): void => {
if (value) {
value = value.replace(/file:\/\//g, "/resource");
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this only catch URLs that end with /?

Something like https://ide.kwc.io/banana wouldn't be caught with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sure the url is correct.

Both
https://ide.kwc.io/banana
https://ide.kwc.io/banana/
use
https://ide.kwc.io/banana/resource
to request the resources

value = value.replace(/file:\/\//g, resourceBaseUrl);
}
oldSrc!.set!.call(img, value);
},
Expand All @@ -66,7 +67,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
},
set: (value: string): void => {
if (value) {
value = value.replace(/file:\/\//g, "/resource");
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
value = value.replace(/file:\/\//g, resourceBaseUrl);
}
oldInnerHtml!.set!.call(style, value);
},
Expand All @@ -80,7 +82,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
if (sheet && !overridden) {
const oldInsertRule = sheet.insertRule;
sheet.insertRule = (rule: string, index?: number): void => {
rule = rule.replace(/file:\/\//g, "/resource");
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
rule = rule.replace(/file:\/\//g, resourceBaseUrl);
oldInsertRule.call(sheet, rule, index);
};
overridden = true;
Expand Down Expand Up @@ -145,8 +148,9 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
(view as any).send = (channel: string, ...args: any[]): void => { // tslint:disable-line no-any
if (args[0] && typeof args[0] === "object" && args[0].contents) {
// TODO
args[0].contents = (args[0].contents as string).replace(/"(file:\/\/[^"]*)"/g, (m1) => `"/resource${m1}"`);
args[0].contents = (args[0].contents as string).replace(/"vscode-resource:([^"]*)"/g, (m, m1) => `"/resource${m1}"`);
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
args[0].contents = (args[0].contents as string).replace(/"(file:\/\/[^"]*)"/g, (m1) => `"${resourceBaseUrl}${m1}"`);
args[0].contents = (args[0].contents as string).replace(/"vscode-resource:([^"]*)"/g, (m, m1) => `"${resourceBaseUrl}${m1}"`);
args[0].contents = (args[0].contents as string).replace(/style-src vscode-core-resource:/g, "style-src 'self'");
}
if (view.contentWindow) {
Expand Down
3 changes: 2 additions & 1 deletion packages/vscode/src/fill/storageDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class StorageDatabase implements workspaceStorage.IStorageDatabase {
}

this.triggerFlush(WillSaveStateReason.SHUTDOWN);
navigator.sendBeacon(`/resource${this.path}`, this.content);
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
navigator.sendBeacon(`${resourceBaseUrl}/${this.path}`, this.content);
});
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/webpack.general.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (options = {}) => ({
// they are parsed as URIs and will throw errors if not fully formed.
// The !! prefix causes it to ignore other loaders (doesn't work).
search: "require\\.toUrl\\(",
replace: "location.protocol + '//' + location.host + '/' + require('!!file-loader?name=[path][name].[ext]!' + ",
replace: "location.protocol + '//' + location.host + location.pathname.replace(/\\/$/,'') + '/' + require('!!file-loader?name=[path][name].[ext]!' + ",
flags: "g",
}, {
search: "require\\.__\\$__nodeRequire",
Expand Down