Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.3 KB
Raw Blame
import './polyfills/prism';
import app from './index';

const PORT = parseInt(process.env.PORT || '8096', 10);

// The shared gateway routes `/lexical/*` here without stripping the prefix;
// the app's routes, and the target group's health check, are at the root.
const GATEWAY_PREFIX = '/lexical';

function withoutGatewayPrefix(req: Request): Request {
  const url = new URL(req.url);
  if (
    url.pathname !== GATEWAY_PREFIX &&
    !url.pathname.startsWith(`${GATEWAY_PREFIX}/`)
  ) {
    return req;
  }
  url.pathname = url.pathname.slice(GATEWAY_PREFIX.length) || '/';
  return new Request(url, req);
}

const env = {
  INTERNAL_AUTH_KEY:
    process.env.INTERNAL_AUTH_KEY || process.env.INTERNAL_API_SECRET_KEY,
  SYNC_SERVICE_AUTH_KEY: process.env.SYNC_SERVICE_AUTH_KEY,
  SYNC_SERVICE_URL: process.env.SYNC_SERVICE_URL,
};

const requiredVars = [
  'INTERNAL_AUTH_KEY',
  'SYNC_SERVICE_AUTH_KEY',
  'SYNC_SERVICE_URL',
] as const;
for (const varName of requiredVars) {
  if (!env[varName]) {
    console.error(`Missing required environment variable: ${varName}`);
    process.exit(1);
  }
}

const server = Bun.serve({
  port: PORT,
  fetch(req) {
    return app.fetch(withoutGatewayPrefix(req), env);
  },
});

console.log(`Lexical service listening on http://localhost:${server.port}`);