@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 79 lines 2.59 KB
Raw
1 import * as Namespace from "alchemy/Namespace";
2 import * as Effect from "effect/Effect";
3 import type { Redis } from "../Redis.ts";
4 import { makeFrameworkSite, type FrameworkSiteProps } from "./FrameworkSite.ts";
5
6 /**
7 * The vinext-on-Node framework module (vinext's Vite build +
8 * `startProdServer`). Not the Cloudflare Worker source.
9 */
10 export const VINEXT_NODE_FRAMEWORK_SPECIFIER = "@alchemy.run/frontend-frameworks/vinext/node";
11
12 export interface VinextProps extends FrameworkSiteProps {
13 /**
14 * Optional Upstash Redis for ISR / `"use cache"`. Bound onto the
15 * hosted Service so Alchemy writes `REDIS_URL` as an App secret.
16 * The resource injects the Redis data-cache adapter automatically.
17 */
18 redis?: Redis;
19 }
20
21 /**
22 * Deploy a [vinext](https://vinext.dev) application to Fly as a
23 * long-running Node process: vinext's Vite build, then vinext's production
24 * server (`startProdServer`). The `dist/` output is baked into the
25 * image; `vinext` is installed unbundled.
26 *
27 * Do not use the Cloudflare Worker entry (`vinext/server/fetch-handler`)
28 * — that is workerd.
29 *
30 * ISR / `"use cache"` persist in Redis when you pass {@link VinextProps.redis}.
31 * The resource injects the adapter automatically. Missing `REDIS_URL`
32 * (local `vinext start` / `alchemy dev`) falls back to memory.
33 *
34 * During `alchemy dev` the site is `vinext dev` and no cloud resources
35 * are declared; `Alchemy.remote()` opts back into the live Service path.
36 *
37 * ### Creating vinext Sites
38 * **Example:** Basic vinext App
39 * ```typescript
40 * const site = yield* Fly.Website.Vinext("Web", {
41 * rootDir: "./app",
42 * });
43 * ```
44 *
45 * **Example:** Redis data cache
46 * ```typescript
47 * const redis = yield* Fly.Redis("Cache", { eviction: true });
48 * const site = yield* Fly.Website.Vinext("Web", {
49 * redis,
50 * });
51 * ```
52 *
53 * **Example:** Custom Domain
54 * ```typescript
55 * const site = yield* Fly.Website.Vinext("Web", {
56 * rootDir: "./app",
57 * domain: "app.example.com",
58 * });
59 * ```
60 *
61 * @resource
62 * @product Website
63 */
64 export const Vinext = (id: string, propsIn: VinextProps = {}) =>
65 Effect.gen(function* () {
66 const { redis, ...props } = propsIn;
67 const site = yield* makeFrameworkSite(id, props, {
68 name: "Vinext",
69 framework: VINEXT_NODE_FRAMEWORK_SPECIFIER,
70 target: VINEXT_NODE_FRAMEWORK_SPECIFIER,
71 install: ["vinext", "react", "react-dom", "react-server-dom-webpack"],
72 });
73 if (redis !== undefined && site.service !== undefined) {
74 yield* site.service.bind`${redis}`({
75 redis: { name: redis.name, id: redis.redisId },
76 });
77 }
78 return site;
79 }).pipe(Namespace.push(id));