Skip to content

Commit 9bdb7c8

Browse files
authored
Server function meta (#1951)
1 parent c9adf13 commit 9bdb7c8

6 files changed

Lines changed: 39 additions & 13 deletions

File tree

examples/experiments/src/routes/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function Home() {
2222
console.log(v);
2323
console.log(await v.hello);
2424
});
25-
fetch(`http://localhost:3000/${import.meta.env.SERVER_BASE_URL}/unknown`, {
25+
fetch(`http://localhost:5173/${import.meta.env.SERVER_BASE_URL}/unknown`, {
2626
headers: { Accept: "application/json" }
2727
}).then(async res => console.log(await res.json()));
2828
return (

examples/with-trpc/src/lib/api.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
import {
2-
createTRPCProxyClient,
3-
httpBatchLink,
4-
loggerLink,
5-
} from '@trpc/client';
1+
import { createTRPCProxyClient, httpBatchLink, loggerLink } from "@trpc/client";
62
import { AppRouter } from "~/server/api/root";
73

84
const getBaseUrl = () => {
95
if (typeof window !== "undefined") return "";
106
// replace example.com with your actual production url
117
if (process.env.NODE_ENV === "production") return "https://example.com";
12-
return `http://localhost:${process.env.PORT ?? 3000}`;
8+
return `http://localhost:${process.env.PORT ?? 5173}`;
139
};
1410

1511
// create the client, export it
1612
export const api = createTRPCProxyClient<AppRouter>({
1713
links: [
18-
// will print out helpful logs when using client
19-
loggerLink(),
20-
// identifies what url will handle trpc requests
21-
httpBatchLink({ url: `${getBaseUrl()}/api/trpc` })
22-
],
14+
// will print out helpful logs when using client
15+
loggerLink(),
16+
// identifies what url will handle trpc requests
17+
httpBatchLink({ url: `${getBaseUrl()}/api/trpc` })
18+
]
2319
});

packages/start/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
export type {
44
APIEvent,
5-
APIHandler, Asset, ContextMatches, DocumentComponentProps, FetchEvent, HandlerOptions, PageEvent, ResponseStub, ServerFunctionMeta
5+
APIHandler,
6+
Asset,
7+
ContextMatches,
8+
DocumentComponentProps,
9+
FetchEvent,
10+
HandlerOptions,
11+
PageEvent,
12+
ResponseStub,
13+
ServerFunctionMeta
614
} from "./server/types.js";
715
export { default as clientOnly } from "./shared/clientOnly.js";
816
export { HttpStatusCode } from "./shared/HttpStatusCode.js";
17+
18+
export { GET } from "./shared/GET.js";
19+
export { getServerFunctionMeta } from "./shared/serverFunction";

packages/start/src/server/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { matchAPIRoute } from "./routes.js";
1313
import type { APIEvent, FetchEvent, HandlerOptions, PageEvent } from "./types.js";
1414

1515
// import { createProdManifest } from "./prodManifest.js";
16+
export { getServerFunctionMeta } from "../shared/serverFunction";
1617
export { StartServer } from "./StartServer.jsx";
1718

1819
import { createRoutes } from "../router.jsx";

packages/start/src/shared/GET.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @refresh skip
2+
/**
3+
*
4+
* Read more: https://docs.solidjs.com/solid-start/reference/server/get
5+
*/
6+
export function GET<T extends (...args: any[]) => any>(fn: T) {
7+
return (fn as any).GET as (...args: Parameters<T>) => ReturnType<T>;
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getRequestEvent } from "solid-js/web";
2+
import type { ServerFunctionMeta } from "../server/types";
3+
4+
/**
5+
*
6+
* Read more: https://docs.solidjs.com/solid-start/reference/server/get-server-function-meta
7+
*/
8+
export function getServerFunctionMeta(): ServerFunctionMeta | undefined {
9+
return getRequestEvent()?.locals.serverFunctionMeta;
10+
}

0 commit comments

Comments
 (0)