Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/experiments/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function Home() {
console.log(v);
console.log(await v.hello);
});
fetch(`http://localhost:3000/${import.meta.env.SERVER_BASE_URL}/unknown`, {
fetch(`http://localhost:5173/${import.meta.env.SERVER_BASE_URL}/unknown`, {
headers: { Accept: "application/json" }
}).then(async res => console.log(await res.json()));
return (
Expand Down
18 changes: 7 additions & 11 deletions examples/with-trpc/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import {
createTRPCProxyClient,
httpBatchLink,
loggerLink,
} from '@trpc/client';
import { createTRPCProxyClient, httpBatchLink, loggerLink } from "@trpc/client";
import { AppRouter } from "~/server/api/root";

const getBaseUrl = () => {
if (typeof window !== "undefined") return "";
// replace example.com with your actual production url
if (process.env.NODE_ENV === "production") return "https://example.com";
return `http://localhost:${process.env.PORT ?? 3000}`;
return `http://localhost:${process.env.PORT ?? 5173}`;
};

// create the client, export it
export const api = createTRPCProxyClient<AppRouter>({
links: [
// will print out helpful logs when using client
loggerLink(),
// identifies what url will handle trpc requests
httpBatchLink({ url: `${getBaseUrl()}/api/trpc` })
],
// will print out helpful logs when using client
loggerLink(),
// identifies what url will handle trpc requests
httpBatchLink({ url: `${getBaseUrl()}/api/trpc` })
]
});
13 changes: 12 additions & 1 deletion packages/start/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

export type {
APIEvent,
APIHandler, Asset, ContextMatches, DocumentComponentProps, FetchEvent, HandlerOptions, PageEvent, ResponseStub, ServerFunctionMeta
APIHandler,
Asset,
ContextMatches,
DocumentComponentProps,
FetchEvent,
HandlerOptions,
PageEvent,
ResponseStub,
ServerFunctionMeta
} from "./server/types.js";
export { default as clientOnly } from "./shared/clientOnly.js";
export { HttpStatusCode } from "./shared/HttpStatusCode.js";

export { GET } from "./shared/GET.js";
export { getServerFunctionMeta } from "./shared/serverFunction";
1 change: 1 addition & 0 deletions packages/start/src/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { matchAPIRoute } from "./routes.js";
import type { APIEvent, FetchEvent, HandlerOptions, PageEvent } from "./types.js";

// import { createProdManifest } from "./prodManifest.js";
export { getServerFunctionMeta } from "../shared/serverFunction";
export { StartServer } from "./StartServer.jsx";

import { createRoutes } from "../router.jsx";
Expand Down
8 changes: 8 additions & 0 deletions packages/start/src/shared/GET.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @refresh skip
/**
*
* Read more: https://docs.solidjs.com/solid-start/reference/server/get
*/
export function GET<T extends (...args: any[]) => any>(fn: T) {
return (fn as any).GET as (...args: Parameters<T>) => ReturnType<T>;
}
10 changes: 10 additions & 0 deletions packages/start/src/shared/serverFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getRequestEvent } from "solid-js/web";
import type { ServerFunctionMeta } from "../server/types";

/**
*
* Read more: https://docs.solidjs.com/solid-start/reference/server/get-server-function-meta
*/
export function getServerFunctionMeta(): ServerFunctionMeta | undefined {
return getRequestEvent()?.locals.serverFunctionMeta;
}
Loading