Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
threepointone committed Sep 11, 2024
1 parent ca4a8c5 commit caadef8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions fixtures/rpc-sanity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ export class MyServer extends Server<Env> {
async testMethod() {
return this.name;
}
onRequest(request: Request): Response | Promise<Response> {
const url = new URL(request.url);
if (url.pathname !== "/test") {
throw new Error("test onRequest");
}
return new Response("test onRequest");
}
}

const SESSION_ID = "session-id";

export default {
async fetch(request: Request, env: Env, _ctx: ExecutionContext) {
const url = new URL(request.url);
const stub = await getServerByName(env.MyServer, SESSION_ID);
const value = await stub.testMethod();
return new Response(`the value is ${value}`);

if (url.pathname === "/rpc") {
const value = await stub.testMethod();
return new Response(`the value is ${value}`);
}
return stub.fetch(request);
}
} satisfies ExportedHandler<Env>;

0 comments on commit caadef8

Please sign in to comment.