Skip to content

Commit

Permalink
feat: implement getRpcInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
katywings committed Dec 31, 2023
1 parent a9b4b05 commit e98f8c1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/start/config/server-fns-runtime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function createServerReference(fn, id, name) {
const ogEvt = getRequestEvent();
if (!ogEvt) throw new Error("Cannot call server function outside of a request");
const evt = cloneEvent(ogEvt);
evt.context.rpcInfo = {
id,
name,
};
evt.serverOnly = true;
return provideRequestEvent(evt, () => {
return fn.apply(thisArg, args);
Expand Down
1 change: 1 addition & 0 deletions packages/start/server/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "vinxi/server";
export { StartServer } from "./StartServer";
export * from "./middleware";
export * from "./rpc";
export * from "./types";
import { createHandler as createBaseHandler } from "./handler";
import { createPageEvent } from "./page-event";
Expand Down
8 changes: 8 additions & 0 deletions packages/start/server/rpc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getRequestEvent } from "solid-js/web";
import type { RpcInfo } from "./types";

export function getRpcInfo(): RpcInfo | undefined {
const event = getRequestEvent();

return event?.context.rpcInfo;
}
5 changes: 5 additions & 0 deletions packages/start/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export interface APIHandler {
(event: APIEvent): Promise<any>;
}

export interface RpcInfo {
id: string;
name: string;
}

declare module "solid-js/web" {
interface RequestEvent extends FetchEvent {
serverOnly?: boolean;
Expand Down

0 comments on commit e98f8c1

Please sign in to comment.