diff --git a/src/index.ts b/src/index.ts
index 616127a..9731221 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -5,6 +5,43 @@ const app = new Hono<{ Bindings: Env }>();
const DEFAULT_INSTRUCTIONS = `You are helpful and have some tools installed.`;
+// Serve the HTML page for the root path
+app.get('/', (c) => {
+ return c.html(`
+
+
+
+
+ OpenAI Realtime API with Cloudflare and Replicate
+
+
+
+
+
+
+
+
+
+
+`);
+});
+
app.post('/rtc-connect', async (c) => {
const authHeader = c.req.header('Authorization');
if (!authHeader || !authHeader.startsWith('Bearer ')) {
diff --git a/test/index.spec.ts b/test/index.spec.ts
index fbee335..71b6692 100644
--- a/test/index.spec.ts
+++ b/test/index.spec.ts
@@ -7,19 +7,51 @@ import worker from '../src/index';
// `Request` to pass to `worker.fetch()`.
const IncomingRequest = Request;
-describe('Hello World worker', () => {
- it('responds with Hello World! (unit style)', async () => {
+describe('OpenAI Realtime API Worker', () => {
+ it('serves the HTML page for root path (unit style)', async () => {
const request = new IncomingRequest('http://example.com');
// Create an empty context to pass to `worker.fetch()`.
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
await waitOnExecutionContext(ctx);
- expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
+ const text = await response.text();
+ expect(text).toContain('');
+ expect(text).toContain('OpenAI Realtime API with Cloudflare and Replicate');
+ expect(response.status).toBe(200);
});
- it('responds with Hello World! (integration style)', async () => {
+ it('serves the HTML page for root path (integration style)', async () => {
const response = await SELF.fetch('https://example.com');
- expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
+ const text = await response.text();
+ expect(text).toContain('');
+ expect(text).toContain('OpenAI Realtime API with Cloudflare and Replicate');
+ expect(response.status).toBe(200);
+ });
+
+ it('returns 401 for rtc-connect without auth header', async () => {
+ const request = new IncomingRequest('http://example.com/rtc-connect', {
+ method: 'POST',
+ body: 'test body'
+ });
+ const ctx = createExecutionContext();
+ const response = await worker.fetch(request, env, ctx);
+ await waitOnExecutionContext(ctx);
+ expect(response.status).toBe(401);
+ const json = await response.json();
+ expect(json.error).toBe('Missing OpenAI API key in Authorization header');
+ });
+
+ it('returns 401 for generate-image without auth header', async () => {
+ const request = new IncomingRequest('http://example.com/generate-image', {
+ method: 'POST',
+ body: 'test prompt'
+ });
+ const ctx = createExecutionContext();
+ const response = await worker.fetch(request, env, ctx);
+ await waitOnExecutionContext(ctx);
+ expect(response.status).toBe(401);
+ const json = await response.json();
+ expect(json.error).toBe('Missing Replicate API token in Authorization header');
});
});