Make sub-paths work
This commit is contained in:
@ -164,7 +164,8 @@ export class FileProviderChannel implements IServerChannel, IDisposable {
|
||||
}
|
||||
|
||||
private transform(resource: UriComponents): URI {
|
||||
// HACK: for now assume /out is relative to the build.
|
||||
// HACK: for now assume /out is relative to the build (used for the
|
||||
// walkthrough content).
|
||||
if (resource.path.indexOf("/out") === 0) {
|
||||
resource.path = this.environmentService.appRoot + resource.path;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ export class ExtensionHostConnection extends Connection {
|
||||
private spawn(buffer: VSBuffer): cp.ChildProcess {
|
||||
const proc = cp.fork(
|
||||
getPathFromAmdModule(require, "bootstrap-fork"),
|
||||
[ "--type=extensionHost", `--uriTransformerPath=${uriTransformerPath()}` ],
|
||||
[ "--type=extensionHost", `--uriTransformerPath=${uriTransformerPath}` ],
|
||||
{
|
||||
env: {
|
||||
...process.env,
|
||||
|
@ -55,7 +55,7 @@ import { Connection, ManagementConnection, ExtensionHostConnection } from "vs/se
|
||||
import { ExtensionEnvironmentChannel, FileProviderChannel , } from "vs/server/src/channel";
|
||||
import { TelemetryClient } from "vs/server/src/insights";
|
||||
import { Protocol } from "vs/server/src/protocol";
|
||||
import { getMediaMime, getUriTransformer, useHttpsTransformer } from "vs/server/src/util";
|
||||
import { getMediaMime, getUriTransformer } from "vs/server/src/util";
|
||||
|
||||
export enum HttpCode {
|
||||
Ok = 200,
|
||||
@ -116,7 +116,6 @@ export abstract class Server {
|
||||
public constructor(public readonly options: ServerOptions) {
|
||||
this.protocol = this.options.allowHttp ? "http" : "https";
|
||||
if (this.options.cert && this.options.certKey) {
|
||||
useHttpsTransformer();
|
||||
const httpolyglot = require.__$__nodeRequire(path.resolve(__dirname, "../node_modules/httpolyglot/lib/index")) as typeof import("httpolyglot");
|
||||
this.server = httpolyglot.createServer({
|
||||
cert: fs.readFileSync(this.options.cert),
|
||||
@ -196,11 +195,11 @@ export abstract class Server {
|
||||
return { redirect: request.url };
|
||||
}
|
||||
|
||||
const parsedUrl = url.parse(request.url || "", true);
|
||||
const parsedUrl = request.url ? url.parse(request.url, true) : {} as url.UrlWithParsedQuery;
|
||||
const fullPath = decodeURIComponent(parsedUrl.pathname || "/");
|
||||
const match = fullPath.match(/^(\/?[^/]*)(.*)$/);
|
||||
let [, base, requestPath] = match
|
||||
? match.map((p) => p.replace(/\/$/, ""))
|
||||
? match.map((p) => p.replace(/\/+$/, ""))
|
||||
: ["", "", ""];
|
||||
if (base.indexOf(".") !== -1) { // Assume it's a file at the root.
|
||||
requestPath = base;
|
||||
@ -388,8 +387,8 @@ export class MainServer extends Server {
|
||||
case "/node_modules":
|
||||
case "/out":
|
||||
return this.getResource(path.join(this.rootPath, base, requestPath));
|
||||
// TODO: make this a /resources endpoint instead. Will require patching?
|
||||
default: return this.getResource(path.join(base, requestPath));
|
||||
case "/resources": return this.getResource(requestPath);
|
||||
default: throw new HttpError("Not found", HttpCode.NotFound);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,25 +1,25 @@
|
||||
// This file is included via a regular Node require. I'm not sure how (or if)
|
||||
// we can write this in Typescript and have it compile to non-AMD syntax.
|
||||
module.exports = (remoteAuthority, https) => {
|
||||
module.exports = (remoteAuthority) => {
|
||||
return {
|
||||
transformIncoming: (uri) => {
|
||||
switch (uri.scheme) {
|
||||
case "https": case "http": return { scheme: "file", path: uri.path };
|
||||
case "file": return { scheme: "vscode-local", path: uri.path };
|
||||
case "code-server": return { scheme: "file", path: uri.path };
|
||||
case "file": return { scheme: "code-server-local", path: uri.path };
|
||||
default: return uri;
|
||||
}
|
||||
},
|
||||
transformOutgoing: (uri) => {
|
||||
switch (uri.scheme) {
|
||||
case "vscode-local": return { scheme: "file", path: uri.path };
|
||||
case "file": return { scheme: https ? "https" : "http", authority: remoteAuthority, path: uri.path };
|
||||
case "code-server-local": return { scheme: "file", path: uri.path };
|
||||
case "file": return { scheme: "code-server", authority: remoteAuthority, path: uri.path };
|
||||
default: return uri;
|
||||
}
|
||||
},
|
||||
transformOutgoingScheme: (scheme) => {
|
||||
switch (scheme) {
|
||||
case "vscode-local": return "file";
|
||||
case "file": return https ? "https" : "http";
|
||||
case "code-server-local": return "file";
|
||||
case "file": return "code-server";
|
||||
default: return scheme;
|
||||
}
|
||||
},
|
@ -1 +0,0 @@
|
||||
module.exports = (remoteAuthority) => require("./uriTransformerHttp")(remoteAuthority, true);
|
@ -45,14 +45,9 @@ export const generateCertificate = async (): Promise<{ cert: string, certKey: st
|
||||
return paths;
|
||||
};
|
||||
|
||||
let transformer: string = "uriTransformerHttp";
|
||||
export const useHttpsTransformer = (): string => transformer = "uriTransformerHttps";
|
||||
export const uriTransformerPath = (): string => {
|
||||
return getPathFromAmdModule(require, `vs/server/src/${transformer}`);
|
||||
};
|
||||
|
||||
export const uriTransformerPath = getPathFromAmdModule(require, "vs/server/src/uriTransformer");
|
||||
export const getUriTransformer = (remoteAuthority: string): URITransformer => {
|
||||
const rawURITransformerFactory = <any>require.__$__nodeRequire(uriTransformerPath());
|
||||
const rawURITransformerFactory = <any>require.__$__nodeRequire(uriTransformerPath);
|
||||
const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(remoteAuthority);
|
||||
return new URITransformer(rawURITransformer);
|
||||
};
|
||||
|
Reference in New Issue
Block a user