Skip to content

Commit 09cd1e8

Browse files
committed
Make sub-paths work
1 parent cd54aec commit 09cd1e8

7 files changed

Lines changed: 379 additions & 42 deletions

File tree

scripts/vscode.patch

Lines changed: 362 additions & 19 deletions
Large diffs are not rendered by default.

src/channel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ export class FileProviderChannel implements IServerChannel, IDisposable {
164164
}
165165

166166
private transform(resource: UriComponents): URI {
167-
// HACK: for now assume /out is relative to the build.
167+
// HACK: for now assume /out is relative to the build (used for the
168+
// walkthrough content).
168169
if (resource.path.indexOf("/out") === 0) {
169170
resource.path = this.environmentService.appRoot + resource.path;
170171
}

src/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class ExtensionHostConnection extends Connection {
9494
private spawn(buffer: VSBuffer): cp.ChildProcess {
9595
const proc = cp.fork(
9696
getPathFromAmdModule(require, "bootstrap-fork"),
97-
[ "--type=extensionHost", `--uriTransformerPath=${uriTransformerPath()}` ],
97+
[ "--type=extensionHost", `--uriTransformerPath=${uriTransformerPath}` ],
9898
{
9999
env: {
100100
...process.env,

src/server.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { Connection, ManagementConnection, ExtensionHostConnection } from "vs/se
5555
import { ExtensionEnvironmentChannel, FileProviderChannel , } from "vs/server/src/channel";
5656
import { TelemetryClient } from "vs/server/src/insights";
5757
import { Protocol } from "vs/server/src/protocol";
58-
import { getMediaMime, getUriTransformer, useHttpsTransformer } from "vs/server/src/util";
58+
import { getMediaMime, getUriTransformer } from "vs/server/src/util";
5959

6060
export enum HttpCode {
6161
Ok = 200,
@@ -116,7 +116,6 @@ export abstract class Server {
116116
public constructor(public readonly options: ServerOptions) {
117117
this.protocol = this.options.allowHttp ? "http" : "https";
118118
if (this.options.cert && this.options.certKey) {
119-
useHttpsTransformer();
120119
const httpolyglot = require.__$__nodeRequire(path.resolve(__dirname, "../node_modules/httpolyglot/lib/index")) as typeof import("httpolyglot");
121120
this.server = httpolyglot.createServer({
122121
cert: fs.readFileSync(this.options.cert),
@@ -196,11 +195,11 @@ export abstract class Server {
196195
return { redirect: request.url };
197196
}
198197

199-
const parsedUrl = url.parse(request.url || "", true);
198+
const parsedUrl = request.url ? url.parse(request.url, true) : {} as url.UrlWithParsedQuery;
200199
const fullPath = decodeURIComponent(parsedUrl.pathname || "/");
201200
const match = fullPath.match(/^(\/?[^/]*)(.*)$/);
202201
let [, base, requestPath] = match
203-
? match.map((p) => p.replace(/\/$/, ""))
202+
? match.map((p) => p.replace(/\/+$/, ""))
204203
: ["", "", ""];
205204
if (base.indexOf(".") !== -1) { // Assume it's a file at the root.
206205
requestPath = base;
@@ -388,8 +387,8 @@ export class MainServer extends Server {
388387
case "/node_modules":
389388
case "/out":
390389
return this.getResource(path.join(this.rootPath, base, requestPath));
391-
// TODO: make this a /resources endpoint instead. Will require patching?
392-
default: return this.getResource(path.join(base, requestPath));
390+
case "/resources": return this.getResource(requestPath);
391+
default: throw new HttpError("Not found", HttpCode.NotFound);
393392
}
394393
}
395394

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// This file is included via a regular Node require. I'm not sure how (or if)
22
// we can write this in Typescript and have it compile to non-AMD syntax.
3-
module.exports = (remoteAuthority, https) => {
3+
module.exports = (remoteAuthority) => {
44
return {
55
transformIncoming: (uri) => {
66
switch (uri.scheme) {
7-
case "https": case "http": return { scheme: "file", path: uri.path };
8-
case "file": return { scheme: "vscode-local", path: uri.path };
7+
case "code-server": return { scheme: "file", path: uri.path };
8+
case "file": return { scheme: "code-server-local", path: uri.path };
99
default: return uri;
1010
}
1111
},
1212
transformOutgoing: (uri) => {
1313
switch (uri.scheme) {
14-
case "vscode-local": return { scheme: "file", path: uri.path };
15-
case "file": return { scheme: https ? "https" : "http", authority: remoteAuthority, path: uri.path };
14+
case "code-server-local": return { scheme: "file", path: uri.path };
15+
case "file": return { scheme: "code-server", authority: remoteAuthority, path: uri.path };
1616
default: return uri;
1717
}
1818
},
1919
transformOutgoingScheme: (scheme) => {
2020
switch (scheme) {
21-
case "vscode-local": return "file";
22-
case "file": return https ? "https" : "http";
21+
case "code-server-local": return "file";
22+
case "file": return "code-server";
2323
default: return scheme;
2424
}
2525
},

src/uriTransformerHttps.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/util.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ export const generateCertificate = async (): Promise<{ cert: string, certKey: st
4545
return paths;
4646
};
4747

48-
let transformer: string = "uriTransformerHttp";
49-
export const useHttpsTransformer = (): string => transformer = "uriTransformerHttps";
50-
export const uriTransformerPath = (): string => {
51-
return getPathFromAmdModule(require, `vs/server/src/${transformer}`);
52-
};
53-
48+
export const uriTransformerPath = getPathFromAmdModule(require, "vs/server/src/uriTransformer");
5449
export const getUriTransformer = (remoteAuthority: string): URITransformer => {
55-
const rawURITransformerFactory = <any>require.__$__nodeRequire(uriTransformerPath());
50+
const rawURITransformerFactory = <any>require.__$__nodeRequire(uriTransformerPath);
5651
const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(remoteAuthority);
5752
return new URITransformer(rawURITransformer);
5853
};

0 commit comments

Comments
 (0)