MCPcopy Index your code
hub / github.com/Waishnav/devspace / createServer

Function createServer

src/server.ts:1551–1726  ·  view source on GitHub ↗
(config = loadConfig())

Source from the content-addressed store, hash-verified

1549}
1550
1551export function createServer(config = loadConfig()): RunningServer {
1552 const allowedHosts = config.allowedHosts.includes("*")
1553 ? undefined
1554 : Array.from(new Set([config.host, ...config.allowedHosts]));
1555 const app = createMcpExpressApp({
1556 host: config.host,
1557 ...(allowedHosts ? { allowedHosts } : {}),
1558 });
1559 const transports = new Map<string, Transport>();
1560 const mcpUrl = new URL("/mcp", config.publicBaseUrl);
1561 const resourceServerUrl = resourceUrlFromServerUrl(mcpUrl);
1562 const oauthProvider = new SingleUserOAuthProvider(config.oauth, mcpUrl, config.stateDir);
1563 const bearerAuth = requireBearerAuth({
1564 verifier: oauthProvider,
1565 requiredScopes: [config.oauth.scopes[0] ?? "devspace"],
1566 resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(resourceServerUrl),
1567 });
1568 const workspaceStore = createWorkspaceStore(config.stateDir);
1569 const workspaces = new WorkspaceRegistry(config, workspaceStore);
1570 const reviewCheckpoints = createReviewCheckpointManager();
1571 const processSessions = new ProcessSessionManager();
1572
1573 if (config.logging.trustProxy) {
1574 app.set("trust proxy", true);
1575 }
1576
1577 app.use((req, res, next) => {
1578 const requestId = randomUUID();
1579 const startedAt = performance.now();
1580 res.locals.requestId = requestId;
1581
1582 res.on("finish", () => {
1583 const path = requestPath(req);
1584 if (!config.logging.requests) return;
1585 if (!config.logging.assets && path.startsWith("/mcp-app-assets")) return;
1586
1587 logEvent(config.logging, "info", "http_request", {
1588 requestId,
1589 method: req.method,
1590 path,
1591 status: res.statusCode,
1592 durationMs: Math.round(performance.now() - startedAt),
1593 ...requestLogFields(req, config),
1594 });
1595 });
1596
1597 next();
1598 });
1599
1600 app.use(
1601 mcpAuthRouter({
1602 provider: oauthProvider,
1603 issuerUrl: new URL(config.publicBaseUrl),
1604 baseUrl: new URL(config.publicBaseUrl),
1605 resourceServerUrl,
1606 scopesSupported: config.oauth.scopes,
1607 resourceName: "DevSpace",
1608 }),

Callers 2

serveFunction · 0.85
server.tsFile · 0.85

Calls 14

shutdownMethod · 0.95
closeMethod · 0.95
loadConfigFunction · 0.85
createWorkspaceStoreFunction · 0.85
requestPathFunction · 0.85
logEventFunction · 0.85
requestLogFieldsFunction · 0.85
setAssetHeadersFunction · 0.85
uiBuildDirectoryFunction · 0.85
sendJsonRpcErrorFunction · 0.85
sessionIdPrefixFunction · 0.85

Tested by

no test coverage detected