Skip to content

Commit

Permalink
feat: implement getServerFunctionMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
katywings committed Jan 4, 2024
1 parent 1371dd7 commit 7b339c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
3 changes: 3 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,9 @@ 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.serverFunctionMeta = {
id: 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 "./serverFunction";
export * from "./types";
import { createHandler as createBaseHandler } from "./handler";
import { createPageEvent } from "./page-event";
Expand Down
6 changes: 6 additions & 0 deletions packages/start/server/serverFunction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getRequestEvent } from "solid-js/web";
import type { ServerFunctionMeta } from "./types";

export function getServerFunctionMeta(): ServerFunctionMeta | undefined {
return getRequestEvent()?.context.serverFunctionMeta;
}
4 changes: 4 additions & 0 deletions packages/start/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export interface APIHandler {
(event: APIEvent): Promise<any>;
}

export interface ServerFunctionMeta {
id: string;
}

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

0 comments on commit 7b339c9

Please sign in to comment.