Skip to content

Commit 08b9e9a

Browse files
authored
Merge pull request #2336 from cdr/webview-404
Fix 404 webviews and tar endpoint
2 parents 2a3608d + 1827913 commit 08b9e9a

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

ci/dev/vscode.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ index 2c64061da7b01aef0bfe3cec851da232ca9461c8..c0ef8faedd406c38bf9c55bbbdbbb060
430430
// Do nothing. If we can't read the file we have no
431431
// language pack config.
432432
diff --git a/src/vs/code/browser/workbench/workbench.ts b/src/vs/code/browser/workbench/workbench.ts
433-
index 0ef8b9dc81419b53b27cf111fb206d72ba56bada..75d2ab3276049115829a38b8b7afee44bb748c2a 100644
433+
index 0ef8b9dc81419b53b27cf111fb206d72ba56bada..62a79602a831bca0dc62ad57dc10a9375f8b9cdb 100644
434434
--- a/src/vs/code/browser/workbench/workbench.ts
435435
+++ b/src/vs/code/browser/workbench/workbench.ts
436436
@@ -17,6 +17,7 @@ import { isStandalone } from 'vs/base/browser/browser';
@@ -468,7 +468,7 @@ index 0ef8b9dc81419b53b27cf111fb206d72ba56bada..75d2ab3276049115829a38b8b7afee44
468468

469469
- const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents, workspaceUri?: UriComponents } = JSON.parse(configElementAttribute);
470470
+ const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents, workspaceUri?: UriComponents } = {
471-
+ webviewEndpoint: `${window.location.origin}${window.location.pathname.replace(/\/+$/, '')}/webview/`,
471+
+ webviewEndpoint: `${window.location.origin}${window.location.pathname.replace(/\/+$/, '')}/webview`,
472472
+ ...JSON.parse(configElementAttribute),
473473
+ };
474474
+

src/node/routes/static.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,33 @@ import * as tarFs from "tar-fs"
77
import * as zlib from "zlib"
88
import { HttpCode, HttpError } from "../../common/http"
99
import { rootPath } from "../constants"
10-
import { authenticated, replaceTemplates } from "../http"
10+
import { authenticated, ensureAuthenticated, replaceTemplates } from "../http"
1111
import { getMediaMime, pathToFsPath } from "../util"
1212

1313
export const router = Router()
1414

1515
// The commit is for caching.
1616
router.get("/(:commit)(/*)?", async (req, res) => {
17+
// Used by VS Code to load extensions into the web worker.
18+
const tar = Array.isArray(req.query.tar) ? req.query.tar[0] : req.query.tar
19+
if (typeof tar === "string") {
20+
ensureAuthenticated(req)
21+
let stream: Readable = tarFs.pack(pathToFsPath(tar))
22+
if (req.headers["accept-encoding"] && req.headers["accept-encoding"].includes("gzip")) {
23+
logger.debug("gzipping tar", field("path", tar))
24+
const compress = zlib.createGzip()
25+
stream.pipe(compress)
26+
stream.on("error", (error) => compress.destroy(error))
27+
stream.on("close", () => compress.end())
28+
stream = compress
29+
res.header("content-encoding", "gzip")
30+
}
31+
res.set("Content-Type", "application/x-tar")
32+
stream.on("close", () => res.end())
33+
return stream.pipe(res)
34+
}
35+
36+
// If not a tar use the remainder of the path to load the resource.
1737
if (!req.params[0]) {
1838
throw new HttpError("Not Found", HttpCode.NotFound)
1939
}
@@ -32,26 +52,6 @@ router.get("/(:commit)(/*)?", async (req, res) => {
3252
res.header("Cache-Control", "public, max-age=31536000")
3353
}
3454

35-
/**
36-
* Used by VS Code to load extensions into the web worker.
37-
*/
38-
const tar = Array.isArray(req.query.tar) ? req.query.tar[0] : req.query.tar
39-
if (typeof tar === "string") {
40-
let stream: Readable = tarFs.pack(pathToFsPath(tar))
41-
if (req.headers["accept-encoding"] && req.headers["accept-encoding"].includes("gzip")) {
42-
logger.debug("gzipping tar", field("path", resourcePath))
43-
const compress = zlib.createGzip()
44-
stream.pipe(compress)
45-
stream.on("error", (error) => compress.destroy(error))
46-
stream.on("close", () => compress.end())
47-
stream = compress
48-
res.header("content-encoding", "gzip")
49-
}
50-
res.set("Content-Type", "application/x-tar")
51-
stream.on("close", () => res.end())
52-
return stream.pipe(res)
53-
}
54-
5555
res.set("Content-Type", getMediaMime(resourcePath))
5656

5757
if (resourcePath.endsWith("manifest.json")) {

0 commit comments

Comments
 (0)