Skip to content

Commit 91f9331

Browse files
bjesuitervignesh07
andauthored
docs: note custom domains use port 8080 (#57)
* refactor: remove CLAWDBOT_* backward-compat env var aliases Only OPENCLAW_* environment variables are now used: - OPENCLAW_PUBLIC_PORT - OPENCLAW_STATE_DIR - OPENCLAW_WORKSPACE_DIR - OPENCLAW_GATEWAY_TOKEN - OPENCLAW_CONFIG_PATH * feat: add CLAWDBOT_* backward compat shim with deprecation warnings Add getEnvWithShim() helper that: - Prefers OPENCLAW_* vars - Falls back to CLAWDBOT_* with console.warn deprecation message - Logs each deprecated var only once to avoid spam Shimmed vars: - OPENCLAW_PUBLIC_PORT / CLAWDBOT_PUBLIC_PORT - OPENCLAW_STATE_DIR / CLAWDBOT_STATE_DIR - OPENCLAW_WORKSPACE_DIR / CLAWDBOT_WORKSPACE_DIR - OPENCLAW_GATEWAY_TOKEN / CLAWDBOT_GATEWAY_TOKEN - OPENCLAW_CONFIG_PATH / CLAWDBOT_CONFIG_PATH * docs: explain MOLTBOT_* vars are not shimmed This repo never shipped with MOLTBOT prefixes, so no existing deployments rely on them. Only CLAWDBOT_* vars have backward compat. * docs: note custom domains use port 8080 * chore(docs): type env shim helpers --------- Co-authored-by: vignesh07 <vigneshnatarajan92@gmail.com>
1 parent fc79766 commit 91f9331

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ Optional:
3737

3838
Notes:
3939
- This template pins OpenClaw to a known-good version by default via Docker build arg `OPENCLAW_GIT_REF`.
40+
- **Backward compatibility:** The wrapper includes a shim for `CLAWDBOT_*` environment variables (logs a deprecation warning when used). `MOLTBOT_*` variables are **not** shimmed — this repo never shipped with MOLTBOT prefixes, so no existing deployments rely on them.
4041

4142
4) Enable **Public Networking** (HTTP). Railway will assign a domain.
43+
- This service is configured to listen on port `8080` (including custom domains).
4244
5) Deploy.
4345

4446
Then:

src/server.js

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,50 @@ import express from "express";
88
import httpProxy from "http-proxy";
99
import * as tar from "tar";
1010

11+
/** @type {Set<string>} */
12+
const warnedDeprecatedEnv = new Set();
13+
14+
/**
15+
* Prefer `primaryKey`, fall back to `deprecatedKey` with a one-time warning.
16+
* @param {string} primaryKey
17+
* @param {string} deprecatedKey
18+
*/
19+
function getEnvWithShim(primaryKey, deprecatedKey) {
20+
const primary = process.env[primaryKey]?.trim();
21+
if (primary) return primary;
22+
23+
const deprecated = process.env[deprecatedKey]?.trim();
24+
if (!deprecated) return undefined;
25+
26+
if (!warnedDeprecatedEnv.has(deprecatedKey)) {
27+
console.warn(
28+
`[deprecation] ${deprecatedKey} is deprecated. Use ${primaryKey} instead.`,
29+
);
30+
warnedDeprecatedEnv.add(deprecatedKey);
31+
}
32+
33+
return deprecated;
34+
}
35+
1136
// Railway deployments sometimes inject PORT=3000 by default. We want the wrapper to
1237
// reliably listen on 8080 unless explicitly overridden.
1338
//
1439
// Prefer OPENCLAW_PUBLIC_PORT (set in the Dockerfile / template) over PORT.
15-
// Keep CLAWDBOT_PUBLIC_PORT as a backward-compat alias for older templates.
1640
const PORT = Number.parseInt(
17-
process.env.OPENCLAW_PUBLIC_PORT ?? process.env.CLAWDBOT_PUBLIC_PORT ?? process.env.PORT ?? "8080",
41+
getEnvWithShim("OPENCLAW_PUBLIC_PORT", "CLAWDBOT_PUBLIC_PORT") ??
42+
process.env.PORT ??
43+
"8080",
1844
10,
1945
);
2046

2147
// State/workspace
22-
// OpenClaw defaults to ~/.openclaw. Keep CLAWDBOT_* as backward-compat aliases.
48+
// OpenClaw defaults to ~/.openclaw.
2349
const STATE_DIR =
24-
process.env.OPENCLAW_STATE_DIR?.trim() ||
25-
process.env.CLAWDBOT_STATE_DIR?.trim() ||
50+
getEnvWithShim("OPENCLAW_STATE_DIR", "CLAWDBOT_STATE_DIR") ||
2651
path.join(os.homedir(), ".openclaw");
2752

2853
const WORKSPACE_DIR =
29-
process.env.OPENCLAW_WORKSPACE_DIR?.trim() ||
30-
process.env.CLAWDBOT_WORKSPACE_DIR?.trim() ||
54+
getEnvWithShim("OPENCLAW_WORKSPACE_DIR", "CLAWDBOT_WORKSPACE_DIR") ||
3155
path.join(STATE_DIR, "workspace");
3256

3357
// Protect /setup with a user-provided password.
@@ -36,7 +60,10 @@ const SETUP_PASSWORD = process.env.SETUP_PASSWORD?.trim();
3660
// Gateway admin token (protects OpenClaw gateway + Control UI).
3761
// Must be stable across restarts. If not provided via env, persist it in the state dir.
3862
function resolveGatewayToken() {
39-
const envTok = process.env.OPENCLAW_GATEWAY_TOKEN?.trim() || process.env.CLAWDBOT_GATEWAY_TOKEN?.trim();
63+
const envTok = getEnvWithShim(
64+
"OPENCLAW_GATEWAY_TOKEN",
65+
"CLAWDBOT_GATEWAY_TOKEN",
66+
);
4067
if (envTok) return envTok;
4168

4269
const tokenPath = path.join(STATE_DIR, "gateway.token");
@@ -59,8 +86,6 @@ function resolveGatewayToken() {
5986

6087
const OPENCLAW_GATEWAY_TOKEN = resolveGatewayToken();
6188
process.env.OPENCLAW_GATEWAY_TOKEN = OPENCLAW_GATEWAY_TOKEN;
62-
// Backward-compat: some older flows expect CLAWDBOT_GATEWAY_TOKEN.
63-
process.env.CLAWDBOT_GATEWAY_TOKEN = process.env.CLAWDBOT_GATEWAY_TOKEN || OPENCLAW_GATEWAY_TOKEN;
6489

6590
// Where the gateway will listen internally (we proxy to it).
6691
const INTERNAL_GATEWAY_PORT = Number.parseInt(process.env.INTERNAL_GATEWAY_PORT ?? "18789", 10);
@@ -77,8 +102,7 @@ function clawArgs(args) {
77102

78103
function configPath() {
79104
return (
80-
process.env.OPENCLAW_CONFIG_PATH?.trim() ||
81-
process.env.CLAWDBOT_CONFIG_PATH?.trim() ||
105+
getEnvWithShim("OPENCLAW_CONFIG_PATH", "CLAWDBOT_CONFIG_PATH") ||
82106
path.join(STATE_DIR, "openclaw.json")
83107
);
84108
}
@@ -148,9 +172,6 @@ async function startGateway() {
148172
...process.env,
149173
OPENCLAW_STATE_DIR: STATE_DIR,
150174
OPENCLAW_WORKSPACE_DIR: WORKSPACE_DIR,
151-
// Backward-compat aliases
152-
CLAWDBOT_STATE_DIR: process.env.CLAWDBOT_STATE_DIR || STATE_DIR,
153-
CLAWDBOT_WORKSPACE_DIR: process.env.CLAWDBOT_WORKSPACE_DIR || WORKSPACE_DIR,
154175
},
155176
});
156177

@@ -492,9 +513,6 @@ function runCmd(cmd, args, opts = {}) {
492513
...process.env,
493514
OPENCLAW_STATE_DIR: STATE_DIR,
494515
OPENCLAW_WORKSPACE_DIR: WORKSPACE_DIR,
495-
// Backward-compat aliases
496-
CLAWDBOT_STATE_DIR: process.env.CLAWDBOT_STATE_DIR || STATE_DIR,
497-
CLAWDBOT_WORKSPACE_DIR: process.env.CLAWDBOT_WORKSPACE_DIR || WORKSPACE_DIR,
498516
},
499517
});
500518

@@ -632,7 +650,7 @@ app.get("/setup/api/debug", requireSetupAuth, async (_req, res) => {
632650
stateDir: STATE_DIR,
633651
workspaceDir: WORKSPACE_DIR,
634652
configPath: configPath(),
635-
gatewayTokenFromEnv: Boolean(process.env.OPENCLAW_GATEWAY_TOKEN?.trim() || process.env.CLAWDBOT_GATEWAY_TOKEN?.trim()),
653+
gatewayTokenFromEnv: Boolean(process.env.OPENCLAW_GATEWAY_TOKEN?.trim()),
636654
gatewayTokenPersisted: fs.existsSync(path.join(STATE_DIR, "gateway.token")),
637655
railwayCommit: process.env.RAILWAY_GIT_COMMIT_SHA || null,
638656
},

0 commit comments

Comments
 (0)