diff --git a/package.json b/package.json index 4ba0eba..444615a 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "main": "main.ts", "type": "module", "scripts": { - "runner": "npx tsx start_runner.ts", - "gateway": "npx tsx start_gateway.ts" + "runner": "npx tsx src/start_runner.ts", + "gateway": "npx tsx src/start_gateway.ts" }, "keywords": [], "author": "Zicklag", diff --git a/registry.ts b/registry.ts deleted file mode 100644 index e84e708..0000000 --- a/registry.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { actor, setup } from "rivetkit"; - -// Create an HTTP actor for handling requests -export const http = actor({ - // Create a raw request handler - onRequest(_c, req) { - // Return whatever URL comes from the request as the text body - return new Response(`Url: ${req.url}`); - }, -}); - -export const registry = setup({ - use: { http }, -}); diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..ae413fa --- /dev/null +++ b/src/config.ts @@ -0,0 +1,3 @@ +export const CONFIG = { + publicEndpoint: process.env.PUBLIC_ENDPOINT || "http://localhost:3000", +}; diff --git a/src/registry.ts b/src/registry.ts new file mode 100644 index 0000000..74350cd --- /dev/null +++ b/src/registry.ts @@ -0,0 +1,8 @@ +import { setup } from "rivetkit"; + +import { authServer } from "./registry/authServer"; +import { http } from "./registry/http"; + +export const registry = setup({ + use: { http, authServer }, +}); diff --git a/src/registry/authServer.ts b/src/registry/authServer.ts new file mode 100644 index 0000000..d113bc8 --- /dev/null +++ b/src/registry/authServer.ts @@ -0,0 +1,12 @@ +import { actor } from "rivetkit"; +import { CONFIG } from "../config"; + +export const authServer = actor({ + actions: { + getMetadata() { + return JSON.stringify({ + issuer: CONFIG.publicEndpoint, + }); + }, + }, +}); diff --git a/src/registry/http.ts b/src/registry/http.ts new file mode 100644 index 0000000..8f63276 --- /dev/null +++ b/src/registry/http.ts @@ -0,0 +1,25 @@ +import { Hono } from "hono"; +import { actor } from "rivetkit"; +import type { registry } from "../registry"; + +/** Create an HTTP actor for handling requests. */ +export const http = actor({ + onRequest(c, req) { + const client = c.client(); + const authServer = client.authServer.getOrCreate("main"); + + const app = new Hono(); + + app.get( + "/.well-known/oauth-authorization-server", + async () => + new Response(await authServer.getMetadata(), { + headers: { + "content-type": "application/json", + }, + }), + ); + + return app.fetch(req); + }, +}); diff --git a/start_gateway.ts b/src/start_gateway.ts similarity index 100% rename from start_gateway.ts rename to src/start_gateway.ts diff --git a/start_runner.ts b/src/start_runner.ts similarity index 100% rename from start_runner.ts rename to src/start_runner.ts