Skip to content

Commit 2d68996

Browse files
authored
mv web (#130)
1 parent 3bbc377 commit 2d68996

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+45
-31
lines changed

.github/workflows/plugin-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
- PKGPATH: ./plugins/bao
7878
RUNNER: ubuntu-24.04
7979
- PKGPATH: ./plugins/docs
80+
- PKGPATH: ./plugins/web
8081
- PKGPATH: ./plugins/runtime
8182

8283
runs-on: ${{ matrix.RUNNER || needs.pick_runner.outputs.random_runner }}

core/server/index.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -545,26 +545,8 @@ try {
545545
console.log("Serving Shinylive assets from shinylive/");
546546
} catch { /* shinylive assets not present — skip */ }
547547

548-
try {
549-
const schemaDir = Deno.env.get("SCHEMA_DIR");
550-
const coreRoot = schemaDir ? join(schemaDir, "..") : join(Deno.cwd(), "core");
551-
const webDistPath = join(coreRoot, "web", "dist");
552-
await Deno.stat(webDistPath);
553-
const serveStatic = (await import("express")).default.static;
554-
app.use(BASE_PATH, serveStatic(webDistPath));
555-
app.get(`${BASE_PATH}/*`, (_req, res, next) => {
556-
if (_req.path.startsWith(`${BASE_PATH}/api/`) || _req.path.startsWith(`${BASE_PATH}/graphql`) || _req.path.startsWith(`${BASE_PATH}/graphiql`) || _req.path.startsWith(`${BASE_PATH}/_internal`)) {
557-
return next();
558-
}
559-
res.sendFile(join(webDistPath, "index.html"));
560-
});
561-
console.log("Serving static files from core/web/dist/");
562-
} catch (e) {
563-
console.warn("Static file serving disabled:", e);
564-
}
565-
566548
app.get("/", (_req, res) => {
567-
res.redirect(`${BASE_PATH}/`);
549+
res.redirect("/plugins/trex/web/");
568550
});
569551

570552
await initAuthFromDB();

core/server/plugin/ui.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Express } from "express";
2+
import { join } from "jsr:@std/path@^1.0";
23
import { PLUGINS_BASE_PATH } from "../config.ts";
34
import { scopeUrlPrefix } from "./utils.ts";
45

@@ -14,21 +15,35 @@ export function getPluginsJson(): string {
1415
return pluginsJson;
1516
}
1617

17-
export function addPlugin(_app: Express, value: any, dir: string, fullName: string = "") {
18+
export function addPlugin(app: Express, value: any, dir: string, fullName: string = "") {
1819
const scopePrefix = scopeUrlPrefix(fullName);
1920
if (value.routes) {
2021
for (const r of value.routes) {
2122
const urlPrefix = r.path || r.source;
2223
const fsPath = `${dir}/${r.dir || r.target}`;
2324
const fullPrefix = `${PLUGINS_BASE_PATH}${scopePrefix}${urlPrefix}`;
2425
console.log(`Registering static route: ${fullPrefix} -> ${fsPath}`);
25-
REGISTERED_UI_ROUTES.push({ pluginName: name, urlPrefix: fullPrefix, fsPath });
26+
REGISTERED_UI_ROUTES.push({ pluginName: fullName, urlPrefix: fullPrefix, fsPath });
2627
try {
2728
// deno-lint-ignore no-explicit-any
2829
(Deno as any).core.ops.op_register_static_route(fullPrefix, fsPath);
2930
} catch (e) {
3031
console.error(`Failed to register static route ${fullPrefix}: ${e}`);
3132
}
33+
34+
// SPA fallback: serve index.html for non-file paths
35+
if (r.spa) {
36+
const indexPath = join(fsPath, "index.html");
37+
try {
38+
const html = Deno.readTextFileSync(indexPath);
39+
app.use(fullPrefix, (_req, res) => {
40+
res.type("html").send(html);
41+
});
42+
console.log(`Registered SPA fallback: ${fullPrefix}/* -> ${indexPath}`);
43+
} catch {
44+
console.warn(`SPA fallback skipped (index.html not found): ${indexPath}`);
45+
}
46+
}
3247
}
3348
}
3449

core/web/src/lib/config.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ services:
3030
- ./functions:/usr/src/functions
3131
- ./plugins-dev:/usr/src/plugins-dev
3232
- ./plugins/docs:/usr/src/plugins/@trex/docs
33+
- ./plugins/web/dist:/usr/src/plugins/@trex/web/dist
3334
depends_on:
3435
postgres:
3536
condition: service_healthy

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@trex/pgwire": "latest",
1717
"@trex/tpm": "latest",
1818
"@trex/docs": "latest",
19-
"@trex/transform": "latest"
19+
"@trex/transform": "latest",
20+
"@trex/web": "latest"
2021
}
2122
}

0 commit comments

Comments
 (0)