@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
mdx 166 lines 4.85 KB
Raw
1 ---
2 title: Custom domains, TCP & private networks
3 description: Reach a Railway Service on your own hostname, expose databases over public TCP, and name private-mesh DNS.
4 ---
5
6 HTTP [Services](/railway/compute/services) already get a generated
7 `*.up.railway.app` hostname. That is enough for most apps. Add a
8 [`CustomDomain`](/providers/railway/customdomain) for a hostname you
9 control. Add a [`TcpProxy`](/providers/railway/tcpproxy) so a laptop
10 or deploy-time migration can reach Postgres, MySQL, Mongo, or Redis.
11 Named [`PrivateNetwork`](/providers/railway/privatenetwork)s add
12 custom DNS on the default `*.railway.internal` mesh.
13
14 ## Publish the Service
15
16 A Service with `port` listens inside the container. Alchemy creates
17 a `*.up.railway.app` domain and points it at that port.
18
19 ```typescript
20 export default class Api extends Railway.Service<Api>()(
21 "Api",
22 {
23 project: Site,
24 main: import.meta.url,
25 port: 3000,
26 },
27 Effect.gen(function* () {
28 return {
29 fetch: Effect.succeed(HttpServerResponse.text("hello")),
30 };
31 }),
32 ) {}
33 ```
34
35 Yield the Service in the Stack. `api.url` is
36 `https://{name}.up.railway.app`.
37
38 ```typescript
39 export default Alchemy.Stack(
40 "MyApp",
41 { providers: Railway.providers(), state: Alchemy.localState() },
42 Effect.gen(function* () {
43 const api = yield* Api;
44 return { url: api.url };
45 }),
46 );
47 ```
48
49 There is no IpAssignment resource. Railway's edge terminates TLS on
50 443.
51
52 ## Custom domains
53
54 A CustomDomain is a user hostname on a Service. Railway issues a
55 Let's Encrypt certificate once DNS is verified.
56
57 ```typescript
58 const site = yield* Railway.Project("Site");
59 const api = yield* Railway.Service("Api", {
60 project: site,
61 image: "hashicorp/http-echo",
62 port: 5678,
63 });
64 const www = yield* Railway.CustomDomain("Www", {
65 service: api,
66 environment: site,
67 domain: "www.example.com",
68 });
69 ```
70
71 Yield `Www` in the Stack. Publish the records in `www.dnsRecords`
72 (the `CNAME` and the verification `TXT`) with your DNS host. `www.url`
73 is `https://www.example.com`. `verified` flips once Railway sees the
74 record.
75
76 `Railway.Website.*` composites can publish those records for you: pass
77 `domain: { name: "www.example.com", dns: Cloudflare.DNS.Adapter() }` (or
78 `AWS.Route53.Adapter()`, `Hetzner.DNS.Adapter()`). See
79 [DNS Adapters](/infrastructure-as-code/dns-adapters).
80
81 `targetPort` is optional and updates in place. Changing `domain`,
82 `service`, or `environment` replaces the CustomDomain.
83
84 ```typescript
85 const www = yield* Railway.CustomDomain("Www", {
86 service: api,
87 environment: site,
88 domain: "www.example.com",
89 targetPort: 8080,
90 });
91 ```
92
93 ## TCP proxies
94
95 A TcpProxy exposes a service over public TCP
96 (`{domain}:{proxyPort}` on `*.proxy.rlwy.net`). Identity is the
97 Railway proxy id. There is no in-place update — changing `service`,
98 `postgres`, `redis`, `environment`, or `applicationPort` replaces
99 the proxy.
100
101 [`Railway.Postgres`](/railway/data/postgres),
102 [`MySQL`](/railway/data/mysql), and [`Mongo`](/railway/data/mongo)
103 already create one when `public` is true (the default). Use
104 `TcpProxy` for Redis, or for a database created with `public:
105 false`.
106
107 ```typescript
108 const site = yield* Railway.Project("Site");
109 const db = yield* Railway.Postgres("Db", { project: site, public: false });
110 const proxy = yield* Railway.TcpProxy("DbProxy", {
111 postgres: db,
112 environment: site,
113 applicationPort: 5432,
114 });
115 ```
116
117 Redis on `6379`:
118
119 ```typescript
120 const cache = yield* Railway.Redis("Cache", { project: site });
121 const proxy = yield* Railway.TcpProxy("CacheProxy", {
122 redis: cache,
123 environment: site,
124 applicationPort: 6379,
125 });
126 ```
127
128 Pass a `Railway.Service` (or `{ serviceId }`) for any other
129 container.
130
131 In-service bindings (`ConnectPostgres`, `ConnectMySQL`,
132 `ConnectMongo`, `ReadWriteRedis`) always use the private
133 `{name}.railway.internal` URL. The TCP proxy is for laptops and CI.
134
135 ## Private networks
136
137 Every environment already has the default `*.railway.internal` mesh
138 — `{serviceName}.railway.internal` is derived from the Service name,
139 no extra resource. [`PrivateNetwork`](/providers/railway/privatenetwork)
140 create-or-gets an additional named network. Attach a Service with
141 [`PrivateNetworkEndpoint`](/providers/railway/privatenetwork)
142 for a custom DNS name.
143
144 ```typescript
145 const net = yield* Railway.PrivateNetwork("Mesh", {
146 environment: site,
147 });
148 const endpoint = yield* Railway.PrivateNetworkEndpoint("ApiDns", {
149 network: net,
150 service: api,
151 name: "api",
152 });
153 ```
154
155 Railway has no per-network delete. Destroy is a no-op; the network
156 is removed when its Project/Environment is deleted.
157
158 ## Where next
159
160 The [tutorial](/railway/tutorial/part-2) deploys a Service that
161 answers on `*.up.railway.app`. Custom domains and TCP proxies hang
162 off the Service / Postgres / Redis. See the
163 [`CustomDomain`](/providers/railway/customdomain),
164 [`TcpProxy`](/providers/railway/tcpproxy),
165 [`PrivateNetwork`](/providers/railway/privatenetwork) (includes
166 `PrivateNetworkEndpoint`) references.