1import * as Namespace from "../../Namespace.ts";
2import { makeFrameworkSite, type FrameworkSiteProps } from "./FrameworkSite.ts";
3
4/** The framework-integration package that drives the TanStack Start build. */
5export const TANSTACK_START_FRAMEWORK_SPECIFIER =
6 "@alchemy.run/frontend-frameworks/tanstack-start";
7
8/** The Node container deploy target for the TanStack Start build. */
9export const TANSTACK_START_NODE_TARGET_SPECIFIER =
10 "@alchemy.run/frontend-frameworks/tanstack-start/node";
11
12export interface TanStackStartProps extends FrameworkSiteProps {}
13
14/**
15 * Deploy a [TanStack Start](https://tanstack.com/start) application to
16 * Railway: the SSR server plus client assets on one `Railway.Service`.
17 *
18 * The build runs through
19 * `@alchemy.run/frontend-frameworks/tanstack-start` with the
20 * `@alchemy.run/frontend-frameworks/tanstack-start/node` deploy target —
21 * both must be installed in your project, alongside
22 * `@tanstack/react-start` (or `@tanstack/solid-start`) and `vite`.
23 *
24 * Your `vite.config.ts` needs no adapter wiring: TanStack Start is pure
25 * Vite, so the integration drives the project's own `vite build`, forces
26 * the SSR bundle to be self-contained, and wraps its fetch handler as a
27 * Node HTTP server on port 3000.
28 *
29 * During `alchemy dev` the site is TanStack Start's own Vite dev server
30 * and no cloud resources are created. `Alchemy.remote()` opts back into
31 * the live Service path.
32 *
33 * ### Creating TanStack Start Sites
34 * **Example:** Basic TanStack Start App
35 * ```typescript
36 * const site = yield* Railway.Website.TanStackStart("Web", {
37 * rootDir: "./app",
38 * });
39 * ```
40 *
41 * **Example:** Custom Domain
42 * ```typescript
43 * const site = yield* Railway.Website.TanStackStart("Web", {
44 * rootDir: "./app",
45 * domain: "app.example.com",
46 * });
47 * ```
48 *
49 * ### Server Configuration
50 * **Example:** Process Environment
51 * ```typescript
52 * const site = yield* Railway.Website.TanStackStart("Web", {
53 * rootDir: "./app",
54 * env: {
55 * GREETING: "Hello from TanStack Start on Railway!",
56 * },
57 * });
58 * ```
59 *
60 * **Example:** Read An Environment Variable From A Server Function
61 * ```typescript
62 * // src/routes/index.tsx
63 * const getApiBase = createServerFn({ method: "GET" }).handler(() => ({
64 * apiBase: process.env.API_BASE,
65 * }));
66 * ```
67 *
68 * @resource
69 * @product Website
70 */
71export const TanStackStart = (id: string, props: TanStackStartProps = {}) =>
72 makeFrameworkSite(id, props, {
73 name: "TanStackStart",
74 framework: TANSTACK_START_FRAMEWORK_SPECIFIER,
75 target: TANSTACK_START_NODE_TARGET_SPECIFIER,
76 }).pipe(Namespace.push(id));