Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 5675123

Browse files
committed
Clean up
1 parent 647bae4 commit 5675123

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

server/build.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ const supportedPlatforms: Record<BuildPlatform, string> = {
2626
"vercel": "Vercel",
2727
};
2828

29+
/**
30+
* Build the app into a worker for serverless platform. Functions include:
31+
* - import routes modules (since deno deploy/clouflare don't support dynamic import)
32+
* - resolve import maps
33+
* - pre-compile client modules
34+
* - bundle client modules
35+
*/
2936
export async function build(serverEntry?: string) {
3037
const workingDir = Deno.cwd();
3138
const alephPkgUri = getAlephPkgUri();
@@ -50,6 +57,7 @@ export async function build(serverEntry?: string) {
5057
await Deno.mkdir(outputDir, { recursive: true });
5158
}
5259

60+
// find route files by the `routes` config
5361
let routeFiles: [filename: string, exportNames: string[]][] = [];
5462
if (config?.routes) {
5563
const { routes } = await initRoutes(config?.routes);
@@ -140,6 +148,7 @@ export async function build(serverEntry?: string) {
140148
);
141149
};
142150

151+
// check if the url is esm.sh package
143152
const isEsmPkg = (url: string) => {
144153
return url.startsWith("https://esm.sh/") && !url.endsWith(".js") && !url.endsWith(".css");
145154
};
@@ -236,6 +245,7 @@ export async function build(serverEntry?: string) {
236245
}],
237246
});
238247

248+
// get depndency graph
239249
const serverDependencyGraph: DependencyGraph | undefined = Reflect.get(globalThis, "serverDependencyGraph");
240250
const clientDependencyGraph: DependencyGraph | undefined = Reflect.get(globalThis, "clientDependencyGraph");
241251

server/error.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
const regStackLoc = /(http:\/\/localhost:60\d{2}\/.+)(:\d+:\d+)/;
22

3-
export const errorHtml = (message: string, prefix?: string): string => {
4-
return errorTemplate(
5-
message.split("\n").map((line, i) => {
6-
const ret = line.match(regStackLoc);
7-
if (ret) {
8-
const url = new URL(ret[1]);
9-
line = line.replace(ret[0], `.${url.pathname}${ret[2]}`);
10-
}
11-
if (i === 0 && prefix) {
12-
return `<strong>${prefix} ${line}</strong>`;
13-
}
14-
return line;
15-
}).join("\n"),
16-
);
3+
export const errorHtml = (message: string, type?: string): string => {
4+
const formatMessage = message.split("\n").map((line, i) => {
5+
const ret = line.match(regStackLoc);
6+
if (ret) {
7+
const url = new URL(ret[1]);
8+
line = line.replace(ret[0], `.${url.pathname}${ret[2]}`);
9+
}
10+
if (i === 0) {
11+
if (type) {
12+
return `<strong>${type} ${line}</strong>`;
13+
}
14+
return `<strong>${line}</strong>`;
15+
}
16+
return line;
17+
}).join("\n");
18+
return errorTemplate(formatMessage, type);
1719
};
1820

19-
const errorTemplate = (message: string) => `
21+
const errorTemplate = (message: string, type?: string) => `
2022
<!DOCTYPE html>
2123
<html lang="en">
2224
<head>
2325
<meta charset="utf-8">
2426
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
25-
<title>SSR Error - Aleph.js</title>
27+
<title>${type} Error - Aleph.js</title>
2628
<style>
2729
body {
2830
overflow: hidden;

server/mod.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ export const serve = (options: ServerOptions = {}) => {
5555
const url = new URL(req.url);
5656
const { host, pathname, searchParams } = url;
5757

58+
// close the hot-reloading websocket connection and tell the client to reload
5859
if (pathname === "/-/hmr") {
5960
const { socket, response } = Deno.upgradeWebSocket(req, {});
6061
socket.addEventListener("open", () => {
6162
socket.send(JSON.stringify({ type: "reload" }));
63+
setTimeout(() => {
64+
socket.close();
65+
}, 50);
6266
});
6367
return response;
6468
}

0 commit comments

Comments
 (0)