| 1 | import * as Namespace from "../../Namespace.ts"; |
| 2 | import { makeFrameworkSite, type FrameworkSiteProps } from "./FrameworkSite.ts"; |
| 3 | |
| 4 | /** |
| 5 | * The vinext-on-Node framework module (vinext's Vite build + |
| 6 | * `startProdServer`). Not the Cloudflare Worker source. |
| 7 | */ |
| 8 | export const VINEXT_NODE_FRAMEWORK_SPECIFIER = |
| 9 | "@alchemy.run/frontend-frameworks/vinext/node"; |
| 10 | |
| 11 | export interface VinextProps extends FrameworkSiteProps {} |
| 12 | |
| 13 | /** |
| 14 | * Deploy a [vinext](https://vinext.dev) application to Cloud Run as a |
| 15 | * long-running Node process: vinext's Vite build, then vinext's production |
| 16 | * server (`startProdServer`). The `dist/` output is baked into the |
| 17 | * image; `vinext`, `react`, `react-dom`, and `react-server-dom-webpack` |
| 18 | * are installed with `npm install` rather than bundled. |
| 19 | * |
| 20 | * Do not use the Cloudflare Worker entry (`vinext/server/fetch-handler`) |
| 21 | * — that is workerd. |
| 22 | * |
| 23 | * During `alchemy dev` the site is `vinext dev` and no cloud resources |
| 24 | * are declared; `Alchemy.remote()` opts back into the live Cloud Run |
| 25 | * service. |
| 26 | * |
| 27 | * ### Creating vinext Sites |
| 28 | * **Example:** Basic vinext App |
| 29 | * ```typescript |
| 30 | * const site = yield* GCP.Website.Vinext("Web", { |
| 31 | * rootDir: "./app", |
| 32 | * }); |
| 33 | * ``` |
| 34 | * |
| 35 | * **Example:** Warm Instance with More Memory |
| 36 | * ```typescript |
| 37 | * const site = yield* GCP.Website.Vinext("Web", { |
| 38 | * rootDir: "./app", |
| 39 | * scaling: { minInstanceCount: 1 }, |
| 40 | * resources: { limits: { cpu: "1", memory: "1Gi" } }, |
| 41 | * }); |
| 42 | * ``` |
| 43 | * |
| 44 | * ### Data Cache |
| 45 | * **Example:** Redis data cache |
| 46 | * ISR / `"use cache"` default to in-process memory, which Cloud Run |
| 47 | * instances do not share. Set `env.REDIS_URL` for a durable Redis store; |
| 48 | * the adapter is injected automatically. |
| 49 | * ```typescript |
| 50 | * const site = yield* GCP.Website.Vinext("Web", { |
| 51 | * env: { |
| 52 | * REDIS_URL: "redis://10.0.0.3:6379", |
| 53 | * }, |
| 54 | * }); |
| 55 | * ``` |
| 56 | * |
| 57 | * @resource |
| 58 | * @product Website |
| 59 | */ |
| 60 | export const Vinext = (id: string, props: VinextProps = {}) => |
| 61 | makeFrameworkSite(id, props, { |
| 62 | name: "Vinext", |
| 63 | framework: VINEXT_NODE_FRAMEWORK_SPECIFIER, |
| 64 | target: VINEXT_NODE_FRAMEWORK_SPECIFIER, |
| 65 | install: ["vinext", "react", "react-dom", "react-server-dom-webpack"], |
| 66 | }).pipe(Namespace.push(id)); |