Imports the previously untracked working tree as-is so that the review changes that follow (requirements -> design -> implementation) can be reviewed as diffs and reverted if needed. No content changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
2.1 KiB
JavaScript
31 lines
2.1 KiB
JavaScript
import 'reflect-metadata';
|
|
import { randomBytes, webcrypto } from 'node:crypto';
|
|
import { Container } from 'inversify';
|
|
import { initializeProtocol } from 'open-collaboration-protocol';
|
|
import { CollaborationServer, CredentialsManager, AuthEndpoint, SimpleLoginEndpoint } from 'open-collaboration-server';
|
|
|
|
const id = value => typeof value === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,199}$/.test(value);
|
|
if (!id(process.env.WF_WORKSPACE_ID) || !id(process.env.WF_TENANT_ID)) throw new Error('Each OCT instance requires its own WF_WORKSPACE_ID and WF_TENANT_ID');
|
|
const hostname = process.env.WF_OCT_HOST ?? '127.0.0.1';
|
|
if (!['127.0.0.1', '0.0.0.0'].includes(hostname)) throw new Error('Invalid isolated OCT listen address');
|
|
if (hostname !== '127.0.0.1' && process.env.WISHFORGE_GATEWAY_ENFORCED !== 'true') throw new Error('Network binding requires an enforced workspace gateway and default-deny network policy');
|
|
const port = Number(process.env.WF_OCT_PORT ?? 8100);
|
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error('Invalid isolated OCT port');
|
|
// Never use OCT's shared development signing key. A restart invalidates all room
|
|
// capabilities because upstream room state is in memory and cannot be recovered.
|
|
process.env.OCT_JWT_PRIVATE_KEY = randomBytes(48).toString('base64url');
|
|
process.env.OCT_ACTIVATE_SIMPLE_LOGIN = 'true';
|
|
process.env.OCT_SERVER_OWNER = `WishForge workspace ${process.env.WF_WORKSPACE_ID}`;
|
|
initializeProtocol({ cryptoModule: webcrypto });
|
|
const { default: serverModule } = await import(new URL('./inversify-module.js', import.meta.resolve('open-collaboration-server')).href);
|
|
const container = new Container();
|
|
container.load(serverModule);
|
|
// This deployment deliberately has one display-name form behind the gateway;
|
|
// no external OAuth providers or account registration flows are activated.
|
|
container.rebind(AuthEndpoint).toService(SimpleLoginEndpoint);
|
|
const credentials = container.get(CredentialsManager);
|
|
credentials.getJwtExpiration = async () => '8h';
|
|
const server = container.get(CollaborationServer);
|
|
// Call the typed API instead of the 0.3.1 Commander parseInt/radix port bug.
|
|
server.startServer({ hostname, port });
|