Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34b52a0

Browse files
committed
Refactor template string with handlebars.
- Refactor static routing, template vars. - Fixed issue where JSON entities may be unescaped - Updated web manifest schema, route handler. - Clean up issues surrounding static paths, types. - Removed static path helper. - Fixed issue where locals may change during request handling. - Added missing types. - Fixed issue where body theme color is stale. - Refactor missing tar endpoint. - Add local route handler.
1 parent d969a5b commit 34b52a0

39 files changed

+739
-377
lines changed

ci/build/build-code-server.sh

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ main() {
2525
fi
2626

2727
parcel build \
28-
--public-url "." \
28+
--public-url "/static/" \
2929
--out-dir dist \
30-
$([[ $MINIFY ]] || echo --no-minify) \
31-
src/browser/register.ts \
32-
src/browser/serviceWorker.ts \
33-
src/browser/pages/login.ts \
34-
src/browser/pages/vscode.ts
30+
"$([[ $MINIFY ]] || echo --no-minify)" \
31+
src/browser/**/*.ts
3532
}
3633

3734
main "$@"

ci/build/build-release.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ bundle_code_server() {
3838

3939
# For source maps and images.
4040
mkdir -p "$RELEASE_PATH/src/browser"
41-
rsync src/browser/media/ "$RELEASE_PATH/src/browser/media"
42-
mkdir -p "$RELEASE_PATH/src/browser/pages"
43-
rsync src/browser/pages/*.html "$RELEASE_PATH/src/browser/pages"
44-
rsync src/browser/robots.txt "$RELEASE_PATH/src/browser"
41+
rsync -r src/browser/public "$RELEASE_PATH/src/browser"
42+
mkdir -p "$RELEASE_PATH/src/browser/views"
43+
rsync -r src/browser/views "$RELEASE_PATH/src/browser"
4544

4645
# Adds the commit to package.json
4746
jq --slurp '.[0] * .[1]' package.json <(

ci/dev/vscode.patch

+15-7
Original file line numberDiff line numberDiff line change
@@ -986,17 +986,17 @@ index 0000000000000000000000000000000000000000..5dd5406befcb593ad6366d9e98f46485
986986
+export const IExtHostNodeProxy = createDecorator<IExtHostNodeProxy>('IExtHostNodeProxy');
987987
diff --git a/src/vs/server/browser/mainThreadNodeProxy.ts b/src/vs/server/browser/mainThreadNodeProxy.ts
988988
new file mode 100644
989-
index 0000000000000000000000000000000000000000..21a139288e5b8f56016491879d69d01da929decb
989+
index 0000000000000000000000000000000000000000..e11988d1b3263c4a2ede064c653653b038c8238c
990990
--- /dev/null
991991
+++ b/src/vs/server/browser/mainThreadNodeProxy.ts
992-
@@ -0,0 +1,55 @@
992+
@@ -0,0 +1,63 @@
993993
+import { VSBuffer } from 'vs/base/common/buffer';
994994
+import { IDisposable } from 'vs/base/common/lifecycle';
995995
+import { FileAccess } from 'vs/base/common/network';
996996
+import { URI, UriComponents } from 'vs/base/common/uri';
997997
+import { INodeProxyService } from 'vs/server/common/nodeProxy';
998998
+import { ExtHostContext, IExtHostContext, MainContext, MainThreadNodeProxyShape } from 'vs/workbench/api/common/extHost.protocol';
999-
+import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
999+
+import {extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
10001000
+
10011001
+@extHostNamedCustomer(MainContext.MainThreadNodeProxy)
10021002
+export class MainThreadNodeProxy implements MainThreadNodeProxyShape {
@@ -1025,14 +1025,22 @@ index 0000000000000000000000000000000000000000..21a139288e5b8f56016491879d69d01d
10251025
+ }
10261026
+
10271027
+ async $fetchExtension(extensionUri: UriComponents): Promise<VSBuffer> {
1028+
+ // Use FileAccess to get the static base path.
1029+
+ const basePath = FileAccess.asBrowserUri("", require).path;
1030+
+
10281031
+ const fetchUri = URI.from({
10291032
+ scheme: window.location.protocol.replace(':', ''),
10301033
+ authority: window.location.host,
1031-
+ // Use FileAccess to get the static base path.
1032-
+ path: FileAccess.asBrowserUri("", require).path,
1033-
+ query: `tar=${encodeURIComponent(extensionUri.path)}`,
1034+
+ path: `${basePath}../../../extension/tar`,
1035+
+ query: `filePath=${encodeURIComponent(extensionUri.path)}`,
10341036
+ });
1035-
+ const response = await fetch(fetchUri.toString(true));
1037+
+
1038+
+ const response = await fetch(fetchUri.toString(true), {
1039+
+ headers: {
1040+
+ Accept: "application/x-tar, application/json;q=0.9"
1041+
+ }
1042+
+ });
1043+
+
10361044
+ if (response.status !== 200) {
10371045
+ throw new Error(`Failed to download extension "${module}"`);
10381046
+ }

ci/dev/watch.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,13 @@ class Watcher {
173173
}
174174

175175
private createBundler(out = "dist"): Bundler {
176-
return new Bundler(
177-
[
178-
path.join(this.rootPath, "src/browser/register.ts"),
179-
path.join(this.rootPath, "src/browser/serviceWorker.ts"),
180-
path.join(this.rootPath, "src/browser/pages/login.ts"),
181-
path.join(this.rootPath, "src/browser/pages/vscode.ts"),
182-
],
183-
{
184-
outDir: path.join(this.rootPath, out),
185-
cacheDir: path.join(this.rootPath, ".cache"),
186-
minify: !!process.env.MINIFY,
187-
logLevel: 1,
188-
publicUrl: ".",
189-
},
190-
)
176+
return new Bundler([path.join(this.rootPath, "src/browser/**/*.ts")], {
177+
outDir: path.join(this.rootPath, out),
178+
cacheDir: path.join(this.rootPath, ".cache"),
179+
minify: !!process.env.MINIFY,
180+
logLevel: 1,
181+
publicUrl: "/static/",
182+
})
191183
}
192184
}
193185

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"devDependencies": {
3333
"@types/body-parser": "^1.19.0",
3434
"@types/cookie-parser": "^1.4.2",
35+
"@types/entities": "^1.1.1",
3536
"@types/express": "^4.17.8",
37+
"@types/express-handlebars": "^3.1.0",
3638
"@types/fs-extra": "^8.0.1",
3739
"@types/http-proxy": "^1.17.4",
3840
"@types/js-yaml": "^3.12.3",
@@ -73,8 +75,10 @@
7375
"@coder/logger": "1.1.16",
7476
"body-parser": "^1.19.0",
7577
"cookie-parser": "^1.4.5",
78+
"entities": "^2.1.0",
7679
"env-paths": "^2.2.0",
7780
"express": "^5.0.0-alpha.8",
81+
"express-handlebars": "^5.2.0",
7882
"fs-extra": "^9.0.1",
7983
"http-proxy": "^1.18.0",
8084
"httpolyglot": "^0.1.2",

src/browser/main.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import "./views/error/index.css"
2+
import "./views/global.css"
3+
import "./views/login/index.css"
4+
5+
import { getOptions, normalize } from "../common/util"
6+
7+
const options = getOptions()
8+
9+
if ("serviceWorker" in navigator) {
10+
const path = normalize(`${options.base}/serviceWorker.js`)
11+
navigator.serviceWorker
12+
.register(path, {
13+
scope: (options.base ?? "") + "/",
14+
})
15+
.then(() => console.debug("[Code Server Service Worker] registered"))
16+
}

src/browser/media/manifest.json

-40
This file was deleted.

src/browser/pages/login.ts

-7
This file was deleted.

src/browser/pages/vscode.html

-59
This file was deleted.

src/browser/pages/vscode.ts

-56
This file was deleted.
File renamed without changes.
File renamed without changes.

src/browser/register.ts

-18
This file was deleted.

src/browser/serviceWorker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22

33
self.addEventListener("install", () => {
4-
console.log("[Service Worker] install")
4+
console.debug("[Code Server Service Worker] install")
55
})
66

77
self.addEventListener("activate", (event: any) => {
File renamed without changes.

src/browser/pages/error.html renamed to src/browser/views/error/index.handlebars

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
http-equiv="Content-Security-Policy"
1111
content="style-src 'self'; manifest-src 'self'; img-src 'self' data:; font-src 'self' data:;"
1212
/>
13-
<title>{{ERROR_TITLE}} - code-server</title>
14-
<link rel="icon" href="{{CS_STATIC_BASE}}/src/browser/media/favicon.ico" type="image/x-icon" />
15-
<link rel="manifest" href="{{CS_STATIC_BASE}}/src/browser/media/manifest.json" crossorigin="use-credentials" />
16-
<link rel="apple-touch-icon" href="{{CS_STATIC_BASE}}/src/browser/media/pwa-icon-384.png" />
17-
<link href="{{CS_STATIC_BASE}}/dist/register.css" rel="stylesheet" />
18-
<meta id="coder-options" data-settings="{{OPTIONS}}" />
13+
<title>{{ERROR_TITLE}} — Code Server</title>
14+
<link rel="icon" href="{{assetPath base '/static/media/favicon.ico'}}" type="image/x-icon" />
15+
<link rel="manifest" href="{{assetPath base '/code-server.webmanifest'}}" crossorigin="use-credentials" />
16+
<link rel="apple-touch-icon" href="{{assetPath base '/static/media/pwa-icon-384.png'}}" />
17+
<link href="{{assetPath base '/static/main.css'}}" rel="stylesheet" />
18+
<meta id="coder-options" data-settings="{{{json coderOptions}}}" />
1919
</head>
2020
<body>
2121
<div class="center-container">
2222
<div class="error-display">
2323
<h2 class="header">{{ERROR_HEADER}}</h2>
2424
<div class="body">{{ERROR_BODY}}</div>
2525
<div class="links">
26-
<a class="link" href="{{BASE}}{{TO}}">go home</a>
26+
<a class="link" href="{{HOME_PATH}}">Go home</a>
2727
</div>
2828
</div>
2929
</div>
30-
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/register.js"></script>
30+
<script data-cfasync="false" src="{{assetPath base '/static/main.js'}}"></script>
3131
</body>
3232
</html>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)