eust-w 78ed117763 feat: make the deployment mode explicit and fail closed
Security-relevant behaviour (development tokens, loopback HTTP, inline
checkpoints, raw provider keys, optional verification profiles) was
keyed off NODE_ENV === 'production', so any deployment that forgot
NODE_ENV silently ran with development rules.

- @wishforge/contracts exports deploymentMode/isProduction/
  requireDeploymentMode. WF_DEPLOYMENT_MODE wins; misspelled values and
  development combined with NODE_ENV=production are rejected; NODE_ENV
  remains a fallback only for libraries and tests.
- All API, runtime, artifact, Git service and operator-script checks use
  isProduction.
- The API, worker, Git service and Runner refuse to start without an
  explicit WF_DEPLOYMENT_MODE; the IDE gateway treats anything other
  than an explicit development mode as production.
- The development seed loads .env.local before checking the mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 14:07:02 +08:00

28 lines
1.3 KiB
JavaScript

import { createGateway } from './server.mjs';
// Fail closed: only an explicit development deployment may use plain HTTP and the local Theia default.
const production = process.env.WF_DEPLOYMENT_MODE !== 'development';
const publicUrl = process.env.WF_IDE_PUBLIC_URL ?? 'http://127.0.0.1:4400';
if (production && !publicUrl.startsWith('https://')) throw new Error('Production gateway requires HTTPS public URL');
const gateway = createGateway({
publicUrl,
apiOrigin: process.env.WF_API_URL ?? 'http://127.0.0.1:4000',
tenantId: process.env.WF_TENANT_ID ?? 'demo',
serviceToken: process.env.WF_WORKSPACE_GATEWAY_TOKEN,
allowedUpstreamOrigins: (process.env.WF_IDE_ALLOWED_UPSTREAM_ORIGINS ?? (production ? '' : 'http://127.0.0.1:4300'))
.split(',')
.filter(Boolean),
allowedServiceNamespace: process.env.WF_IDE_ALLOWED_SERVICE_NAMESPACE,
allowedCollaborationOrigins: (process.env.WF_COLLABORATION_ALLOWED_UPSTREAM_ORIGINS ?? '').split(',').filter(Boolean),
});
gateway.server.listen(
Number(process.env.WF_IDE_GATEWAY_PORT ?? 4400),
process.env.WF_IDE_GATEWAY_HOST ?? '127.0.0.1',
() => console.log(`Workspace gateway listening at ${publicUrl}`),
);
for (const signal of ['SIGTERM', 'SIGINT'])
process.on(signal, async () => {
await gateway.close();
process.exit(0);
});