1import * as Alchemy from "alchemy";
2import * as Output from "alchemy/Output";
3import * as Railway from "alchemy/Railway";
4import * as Config from "effect/Config";
5import * as Effect from "effect/Effect";
6import * as Option from "effect/Option";
7import Api from "./src/api.ts";
8import { Db, Site } from "./src/shared.ts";
9
10const RAILWAY_TEST_DOMAIN = Config.String("RAILWAY_TEST_DOMAIN").pipe(
11 Config.option,
12 Config.map(Option.getOrUndefined),
13);
14
15export default Alchemy.Stack(
16 "RailwayWebsiteViteExample",
17 {
18 providers: Railway.providers(),
19 state: Alchemy.localState(),
20 },
21 Effect.gen(function* () {
22 const domain = yield* RAILWAY_TEST_DOMAIN;
23 const project = yield* Site;
24 const db = yield* Db;
25 const api = yield* Api;
26 const web = yield* Railway.Website.Vite("Web", {
27 project,
28 domain,
29 env: {
30 VITE_API_URL: Output.map(api.url, (url) => url ?? ""),
31 },
32 memo: {
33 include: [
34 "index.html",
35 "src/**",
36 "public/**",
37 "package.json",
38 "vite.config.ts",
39 ],
40 },
41 });
42
43 return {
44 url: web.url,
45 apiUrl: api.url,
46 serviceId: web.service?.serviceId,
47 postgresId: db.serviceId,
48 };
49 }),
50);