Skip to content

PrivateNetwork

Source: src/Railway/PrivateNetwork.ts

A Railway.PrivateNetwork is a named private mesh in an environment. Every environment already has the default *.railway.internal mesh — this resource create-or-gets an additional named network (custom DNS) and is the parent of PrivateNetworkEndpoint.

Railway has no per-network delete. Destroy is a no-op; the network is removed when its Project/Environment is deleted. create-or-get is idempotent for a given (environment, name).

Pass a Project (or Environment). Alchemy generates a unique name. dnsName is the network suffix endpoints hang off.

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

Pass name when you need a stable network name. Changing it later replaces the resource — Railway cannot rename a network.

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

Attach a Service with a custom DNS name via PrivateNetworkEndpoint.

const api = yield* Railway.Service("Api", {
project: site,
image: "hashicorp/http-echo",
});
const endpoint = yield* Railway.PrivateNetworkEndpoint("ApiDns", {
network: net,
service: api,
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,
});