Skip to content

Commit 34039c3

Browse files
committed
docs: document port detection and baseUrl features
1 parent 27a12f4 commit 34039c3

File tree

2 files changed

+81
-14
lines changed

2 files changed

+81
-14
lines changed

.changeset/smooth-rats-attack.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
"@workflow/world-local": patch
44
---
55

6-
Add automatic port discovery
6+
Add automatic port detection and baseUrl configuration support
7+
8+
- Automatically detect application port using pid-port (no manual configuration needed)
9+
- Support HTTPS and custom hostnames via baseUrl override
10+
- Add WORKFLOW_EMBEDDED_BASE_URL environment variable
11+
- Refactor createEmbeddedWorld API to accept Partial<Config> for better flexibility
12+
- Implement priority-based URL resolution: explicit baseUrl → config port → auto-detected port → PORT env var → 3000 fallback

docs/content/docs/deploying/world/embedded-world.mdx

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,63 @@ export WORKFLOW_EMBEDDED_DATA_DIR=./custom-workflow-data
7272
```typescript
7373
import { createEmbeddedWorld } from '@workflow/world-local';
7474

75-
const world = createEmbeddedWorld('./custom-workflow-data');
75+
const world = createEmbeddedWorld({ dataDir: './custom-workflow-data' });
7676
```
7777

7878
### Port
7979

80-
The local world automatically detects your server port from the `PORT` environment variable:
80+
By default, the embedded world **automatically detects** which port your application is listening on using process introspection. This works seamlessly with frameworks like SvelteKit, Vite, and others that use non-standard ports.
8181

82-
```bash
83-
export PORT=3000
82+
**Auto-detection example** (recommended):
8483

85-
npm run dev
84+
```typescript
85+
import { createEmbeddedWorld } from '@workflow/world-local';
86+
87+
// Port is automatically detected - no configuration needed!
88+
const world = createEmbeddedWorld();
8689
```
8790

88-
You can also specify it explicitly when creating the world programmatically:
91+
If auto-detection fails, the world will fall back to the `PORT` environment variable, then to port `3000`.
92+
93+
**Manual port override** (when needed):
94+
95+
You can override the auto-detected port by specifying it explicitly:
8996

9097
```typescript
9198
import { createEmbeddedWorld } from '@workflow/world-local';
9299

93-
const world = createEmbeddedWorld(undefined, 3000);
100+
const world = createEmbeddedWorld({ port: 3000 });
101+
```
102+
103+
### Base URL
104+
105+
For advanced use cases like HTTPS or custom hostnames, you can override the entire base URL. When set, this takes precedence over all port detection and configuration.
106+
107+
**Use cases:**
108+
- HTTPS dev servers (e.g., `next dev --experimental-https`)
109+
- Custom hostnames (e.g., `local.example.com`)
110+
- Non-localhost development
111+
112+
**Environment variable:**
113+
114+
```bash
115+
export WORKFLOW_EMBEDDED_BASE_URL=https://local.example.com:3000
116+
```
117+
118+
**Programmatically:**
119+
120+
```typescript
121+
import { createEmbeddedWorld } from '@workflow/world-local';
122+
123+
// HTTPS
124+
const world = createEmbeddedWorld({
125+
baseUrl: 'https://localhost:3000'
126+
});
127+
128+
// Custom hostname
129+
const world = createEmbeddedWorld({
130+
baseUrl: 'https://local.example.com:3000'
131+
});
94132
```
95133

96134
## Usage
@@ -172,26 +210,49 @@ Creates a local world instance:
172210

173211
```typescript
174212
function createEmbeddedWorld(
175-
dataDir?: string,
176-
port?: number
213+
args?: Partial<{
214+
dataDir: string;
215+
port: number;
216+
baseUrl: string;
217+
}>
177218
): World
178219
```
179220

180221
**Parameters:**
181222

182-
- `dataDir` - Directory for storing workflow data (default: `.workflow-data/`)
183-
- `port` - Server port for queue transport (default: from `PORT` env var)
223+
- `args` - Optional configuration object:
224+
- `dataDir` - Directory for storing workflow data (default: `.workflow-data/` or `WORKFLOW_EMBEDDED_DATA_DIR` env var)
225+
- `port` - Port override for queue transport (default: auto-detected`PORT` env var`3000`)
226+
- `baseUrl` - Full base URL override for queue transport (default: `http://localhost:{port}` or `WORKFLOW_EMBEDDED_BASE_URL` env var)
184227

185228
**Returns:**
186229

187230
- `World` - A world instance implementing the World interface
188231

189-
**Example:**
232+
**Examples:**
190233

191234
```typescript
192235
import { createEmbeddedWorld } from '@workflow/world-local';
193236

194-
const world = createEmbeddedWorld('./my-data', 3000);
237+
// Use all defaults (recommended - auto-detects port)
238+
const world = createEmbeddedWorld();
239+
240+
// Custom data directory
241+
const world = createEmbeddedWorld({ dataDir: './my-data' });
242+
243+
// Override port
244+
const world = createEmbeddedWorld({ port: 3000 });
245+
246+
// HTTPS with custom hostname
247+
const world = createEmbeddedWorld({
248+
baseUrl: 'https://local.example.com:3000'
249+
});
250+
251+
// Multiple options
252+
const world = createEmbeddedWorld({
253+
dataDir: './my-data',
254+
baseUrl: 'https://localhost:3000'
255+
});
195256
```
196257

197258
## Learn More

0 commit comments

Comments
 (0)