Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package-lock.json
yarn.lock

# TESTING
/coverage
coverage/
*.lcov
.nyc_output

Expand Down
6 changes: 3 additions & 3 deletions apps/docs/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createMDX } from "fumadocs-mdx/next";
import { type NextConfig } from "next";
import { validateRegistry } from "@/registry/lib/validator";
import { validateRegistry } from "@proofkit/registry";

const withMDX = createMDX();
validateRegistry();
// validateRegistry();

const config: NextConfig = {
reactStrictMode: true,
serverExternalPackages: ["typescript", "twoslash", "shiki"],
transpilePackages: ["@proofkit/fmdapi"],
transpilePackages: ["@proofkit/fmdapi", "@proofkit/registry"],
async redirects() {
return [
{
Expand Down
1 change: 1 addition & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"test": "vitest run"
},
"dependencies": {
"@proofkit/registry": "workspace:*",
"@proofkit/typegen": "workspace:*",
"@proofkit/webviewer": "workspace:*",
"@radix-ui/react-separator": "^1.1.7",
Expand Down
69 changes: 57 additions & 12 deletions apps/docs/src/app/r/[[...name]]/registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Hono } from "hono";

import { getRegistryIndex, getStaticComponent } from "@/registry/lib/utils";
import {
getComponentMeta,
getRegistryIndex,
getStaticComponent,
} from "@proofkit/registry";
import { createMiddleware } from "hono/factory";
import type { TemplateMetadata } from "@proofkit/registry";

const app = new Hono().basePath("/r");

Expand All @@ -16,18 +22,57 @@ app.get("/", async (c) => {
}
});

// Handle registry requests at base path "/r"
app.get("/:path", async (c) => {
const path = c.req.param("path");
const componentMeta = (basePath: string) =>
createMiddleware<{
Variables: { meta: TemplateMetadata; path: string };
}>(async (c, next) => {
console.log("c.req.path", c.req.path);
console.log("basePath", basePath);
const path = c.req.path.replace(basePath, "").replace(/\.json$/, "");
console.log("path", path);
c.set("path", path);

// Support both with and without .json suffix; path may contain slashes
const pathWithoutJson = path.replace(/\.json$/, "");
try {
const data = await getStaticComponent(pathWithoutJson);
return c.json(data);
} catch (error) {
console.error(error);
return c.json({ error: "Component not found." }, { status: 404 });
try {
const meta = await getComponentMeta(path);
c.set("meta", meta);
await next();
} catch (error) {
console.error(error);
return c.json({ error: "Component not found." }, { status: 404 });
}
});

// Handle meta requests first (more specific route)
app.get("/meta/*", componentMeta("/r/meta"), async (c) => {
const meta = c.get("meta");
return c.json(meta, 200);
});

// Handle registry requests at base path "/r" (less specific route)
app.get("/*", componentMeta("/r"), async (c) => {
const path = c.get("path");
const requestUrl = new URL(c.req.url);

const meta = c.get("meta");
if (meta.type === "static") {
try {
const data = await getStaticComponent(path);

return c.json({
...data,
registryDependencies: data.registryDependencies?.map((x) =>
x.replace("{proofkit}", requestUrl.origin),
),
});
} catch (error) {
console.error(error);
return c.json({ error: "Component not found." }, { status: 404 });
}
} else {
return c.json(
{ error: "Dynamic components are not supported yet." },
{ status: 501 },
);
}
});

Expand Down
71 changes: 0 additions & 71 deletions apps/docs/src/registry/lib/types.ts

This file was deleted.

121 changes: 0 additions & 121 deletions apps/docs/src/registry/lib/utils.ts

This file was deleted.

Loading
Loading