Skip to content

Railway.Networking reference

Source: src/Railway/CustomDomain.ts

A Railway.CustomDomain is a user hostname on a CustomDomainService. Railway issues a Let’s Encrypt certificate once DNS is verified.

Pass the parent Service, the environment id, and the hostname. Yield the CustomDomain next to the Service. Point DNS at the values in verificationDnsHost / verificationToken.

const site = yield* Railway.Project("Site");
const api = yield* Railway.Service("Api", {
project: site,
image: "hashicorp/http-echo",
});
const www = yield* Railway.CustomDomain("Www", {
service: api,
environment: site,
domain: "www.example.com",
});

targetPort is optional and updates in place. Railway’s edge forwards HTTPS on 443 to this port on the Service.

const www = yield* Railway.CustomDomain("Www", {
service: api,
environment: site,
domain: "www.example.com",
targetPort: 8080,
});

Declare the CustomDomain once. Resource-valued props accept the resource or an Effect producing it.

src/domain.ts
import * as Railway from "alchemy/Railway";
import { Api } from "./api.ts";
import { Site } from "./project.ts";
export const Www = Railway.CustomDomain("Www", {
service: Api,
environment: Site,
domain: "www.example.com",
});

Source: src/Railway/PrivateNetwork.ts

Enable Railway’s platform-managed private network for an environment. This resource manages the environment’s networking setting, not a separately created network. Use one PrivateNetwork resource per environment.

Destroy restores the setting captured before reconciliation. A network that was already enabled stays enabled; one enabled by this resource is disabled. Platform network objects follow the environment’s lifecycle.

Pass a Project or Environment. dnsName is Railway’s network DNS label.

const site = yield* Railway.Project("Site");
const net = yield* Railway.PrivateNetwork("Mesh", {
environment: site,
});

Configure a deployed service’s DNS prefix via PrivateNetworkEndpoint.

const endpoint = yield* Railway.PrivateNetworkEndpoint("ApiDns", {
network: net,
service: { serviceId: "deployed-service-id" },
name: "api",
});

Resource-valued props accept the resource or an Effect producing it.

src/network.ts
import * as Railway from "alchemy/Railway";
export const Site = Railway.Project("Site");
export const Mesh = Railway.PrivateNetwork("Mesh", {
environment: Site,
});

Source: src/Railway/TcpProxy.ts

A Railway.TcpProxy exposes a service over public TCP. Identity is the Railway proxy id. There is no in-place update — changing service, postgres, redis, environment, or applicationPort replaces the proxy.

Needed so laptop tests and ConnectPostgres from outside the private network can reach Postgres/Redis.

Attach a proxy to a Postgres service on 5432. domain and proxyPort are the public endpoint ({domain}:{proxyPort}).

const site = yield* Railway.Project("Site");
const db = yield* Railway.Postgres("Db", { project: site });
const proxy = yield* Railway.TcpProxy("DbProxy", {
postgres: db,
environment: site,
applicationPort: 5432,
});

Same shape on 6379.

const site = yield* Railway.Project("Site");
const cache = yield* Railway.Redis("Cache", { project: site });
const proxy = yield* Railway.TcpProxy("CacheProxy", {
redis: cache,
environment: site,
applicationPort: 6379,
});

Pass a Railway.Service or a { serviceId } stub.

const site = yield* Railway.Project("Site");
const proxy = yield* Railway.TcpProxy("ApiProxy", {
service: { serviceId: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" },
environment: site,
applicationPort: 8080,
});

Resource-valued props accept the resource or an Effect producing it.

src/db.ts
import * as Railway from "alchemy/Railway";
export const Site = Railway.Project("Site");
export const Db = Railway.Postgres("Db", { project: Site });
export const DbProxy = Railway.TcpProxy("DbProxy", {
postgres: Db,
environment: Site,
applicationPort: 5432,
});