| 1 | import type { InputProps } from "../../Input.ts"; |
| 2 | import * as Namespace from "../../Namespace.ts"; |
| 3 | import { makeFrameworkSite, type FrameworkSiteProps } from "./FrameworkSite.ts"; |
| 4 | |
| 5 | /** The framework-integration package that drives the SolidStart build. */ |
| 6 | export const SOLIDSTART_FRAMEWORK_SPECIFIER = |
| 7 | "@alchemy.run/frontend-frameworks/solidstart"; |
| 8 | |
| 9 | /** The AWS Lambda deploy target for the SolidStart build. */ |
| 10 | export const SOLIDSTART_AWS_TARGET_SPECIFIER = |
| 11 | "@alchemy.run/frontend-frameworks/solidstart/aws"; |
| 12 | |
| 13 | export interface SolidStartProps extends FrameworkSiteProps { |
| 14 | /** |
| 15 | * Nitro options forwarded into the nitro plugin the integration appends |
| 16 | * (prerendering, route rules, storage, ...). `preset` is owned by the |
| 17 | * deploy target and may not be set here. JSON-serializable values only — |
| 18 | * no functions or plugin instances. |
| 19 | * |
| 20 | * This is a prop (rather than project config) because the integration |
| 21 | * owns the nitro plugin instance: a `nitroV2Plugin()` in your project's |
| 22 | * `vite.config.*` is rejected, so this prop is the one home for nitro |
| 23 | * options — and it accepts values derived from other resources' Outputs, |
| 24 | * which a config file cannot. |
| 25 | */ |
| 26 | nitro?: Record<string, unknown>; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Deploy a [SolidStart](https://start.solidjs.com) application to AWS: the |
| 31 | * SSR server on a streaming Lambda Function URL, static assets (prerendered |
| 32 | * pages included) in S3, and a CloudFront distribution whose edge router |
| 33 | * serves uploaded files from S3 and forwards everything else to the server. |
| 34 | * |
| 35 | * The build runs through `@alchemy.run/frontend-frameworks/solidstart` with |
| 36 | * the `@alchemy.run/frontend-frameworks/solidstart/aws` deploy target — both |
| 37 | * must be installed in your project, alongside `@solidjs/start` and |
| 38 | * `@solidjs/vite-plugin-nitro-2`. |
| 39 | * |
| 40 | * Your `vite.config.ts` needs no adapter wiring: the integration drives the |
| 41 | * project's own `vite build` and appends its own nitro plugin instance |
| 42 | * carrying nitro's `aws-lambda` preset with response streaming enabled. |
| 43 | * |
| 44 | * ### Creating SolidStart Sites |
| 45 | * **Example:** Basic SolidStart App |
| 46 | * ```typescript |
| 47 | * const site = yield* AWS.Website.SolidStart("Web", { |
| 48 | * rootDir: "./app", |
| 49 | * }); |
| 50 | * ``` |
| 51 | * |
| 52 | * **Example:** Custom Domain |
| 53 | * ```typescript |
| 54 | * const site = yield* AWS.Website.SolidStart("Web", { |
| 55 | * rootDir: "./app", |
| 56 | * domain: { |
| 57 | * name: "app.example.com", |
| 58 | * hostedZoneId: zone.hostedZoneId, |
| 59 | * }, |
| 60 | * }); |
| 61 | * ``` |
| 62 | * |
| 63 | * ### Server Configuration |
| 64 | * **Example:** Tune The Server Function |
| 65 | * ```typescript |
| 66 | * const site = yield* AWS.Website.SolidStart("Web", { |
| 67 | * rootDir: "./app", |
| 68 | * memorySize: 2048, |
| 69 | * env: { |
| 70 | * API_BASE: api.url, |
| 71 | * }, |
| 72 | * }); |
| 73 | * ``` |
| 74 | * |
| 75 | * ### Prerendering |
| 76 | * The integration owns the nitro plugin instance (a `nitroV2Plugin()` in |
| 77 | * your `vite.config.*` is rejected), so nitro options — prerendering |
| 78 | * included — go on the `nitro` prop. Prerendered pages are uploaded to S3 |
| 79 | * and served from the edge automatically. |
| 80 | * |
| 81 | * **Example:** Prerender Routes |
| 82 | * ```typescript |
| 83 | * const site = yield* AWS.Website.SolidStart("Web", { |
| 84 | * rootDir: "./app", |
| 85 | * nitro: { prerender: { routes: ["/", "/about"] } }, |
| 86 | * }); |
| 87 | * ``` |
| 88 | * |
| 89 | * @resource |
| 90 | */ |
| 91 | export const SolidStart = ( |
| 92 | id: string, |
| 93 | props: InputProps<SolidStartProps> = {}, |
| 94 | ) => { |
| 95 | const p = props as SolidStartProps; |
| 96 | return makeFrameworkSite(id, props, { |
| 97 | name: "SolidStart", |
| 98 | framework: SOLIDSTART_FRAMEWORK_SPECIFIER, |
| 99 | target: SOLIDSTART_AWS_TARGET_SPECIFIER, |
| 100 | options: { nitro: p.nitro }, |
| 101 | }).pipe(Namespace.push(id)); |
| 102 | }; |