{"record":{"id":"04d952bb133a95f5","repo":"cube-js/cube","slug":"native-api-gateway-is-not-enabled","errorCode":null,"errorMessage":"Native api gateway is not enabled","messagePattern":"Native api gateway is not enabled","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-api-gateway/src/sql-server.ts","lineNumber":68,"sourceCode":"    setupLogger(\n      ({ event }) => apiGateway.log(event),\n      process.env.CUBEJS_LOG_LEVEL === 'trace' ? 'trace' : 'warn',\n      process.env.NODE_ENV === 'production'\n    );\n\n    // Actually, proxy is enabled in gateway\n    // But passing port into registerInterface will start native gateway\n    if (getEnv('nativeApiGateway')) {\n      this.gatewayPort = options.gatewayPort || 7575;\n    }\n  }\n\n  public getNativeGatewayPort(): number {\n    if (this.gatewayPort) {\n      return this.gatewayPort;\n    }\n\n    throw new Error('Native api gateway is not enabled');\n  }\n\n  private getSqlInterfaceInstance(): SqlInterfaceInstance {\n    if (!this.sqlInterfaceInstance) {\n      throw new Error('SQL interface is not initialized. Please enable the SQL interface in your settings.');\n    }\n\n    return this.sqlInterfaceInstance;\n  }\n\n  public async execSql(sqlQuery: string, stream: any, securityContext?: any, cacheMode?: CacheMode, timezone?: string, throwContinueWait?: boolean, requestId?: string) {\n    await execSql(this.getSqlInterfaceInstance(), sqlQuery, stream, securityContext, cacheMode, timezone, throwContinueWait, requestId);\n  }\n\n  public async sql4sql(sqlQuery: string, disablePostProcessing: boolean, securityContext?: unknown): Promise<Sql4SqlResponse> {\n    return sql4sql(this.getSqlInterfaceInstance(), sqlQuery, disablePostProcessing, securityContext);\n  }\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-api-gateway/src/sql-server.ts#L50-L86","documentation":"getNativeGatewayPort returns the port of the native (Rust) API gateway, but that port is only assigned in the SQLServer constructor when the nativeApiGateway env flag is enabled. If the flag is off, gatewayPort stays undefined and this getter throws 'Native api gateway is not enabled'. It signals that code is asking for native-gateway functionality the deployment never enabled.","triggerScenarios":"Calling getNativeGatewayPort() (directly or via code that proxies/queries the native gateway) on a SQLServer instance constructed without the nativeApiGateway env var set (CUBEJS_NATIVE_API_GATEWAY truthy).","commonSituations":"Running Cube from source or embedding @cubejs-server-core without the native gateway enabled while tooling (e.g. SQL API tooling, tests, custom integrations) assumes it; upgrading to a version where the native gateway is expected but not configured; forgetting to set the env var in a container or serverless deployment.","solutions":["Enable the native API gateway by setting the environment variable (nativeApiGateway / CUBEJS_NATIVE_API_GATEWAY=true).","Explicitly configure the port via gatewayPort option (defaults to 7575) so the getter returns a known value.","If the native gateway is intentionally disabled, remove or gate the code path that calls getNativeGatewayPort()."],"exampleFix":"// before\nconst port = sqlServer.getNativeGatewayPort();\n// after (env)\nprocess.env.CUBEJS_NATIVE_API_GATEWAY = 'true';\nconst port = sqlServer.getNativeGatewayPort();","handlingStrategy":"validation","validationCode":"const nativeGatewayEnabled = () =>\n  ['true', '1', 'on'].includes(String(process.env.CUBEJS_NATIVE_API_GATEWAY ?? process.env.nativeApiGateway ?? '').toLowerCase());\nif (!nativeGatewayEnabled()) throw new Error('Enable CUBEJS_NATIVE_API_GATEWAY before using the native gateway');","typeGuard":"function hasNativeGateway(s: { getNativeGatewayPort?: () => number }): s is Required<{ getNativeGatewayPort: () => number }> {\n  return typeof (s as any).gatewayPort === 'number' || nativeGatewayEnabled();\n}","tryCatchPattern":"let port: number;\ntry {\n  port = sqlServer.getNativeGatewayPort();\n} catch (e) {\n  if (e.message === 'Native api gateway is not enabled') {\n    port = 7575; // or bail out / fall back to REST gateway\n  } else throw e;\n}","preventionTips":["Set CUBEJS_NATIVE_API_GATEWAY=true wherever the native gateway is required.","Check env var presence in deployment config (Docker, k8s, serverless) before boot.","Gate any getNativeGatewayPort() call behind a check that the feature is on.","Log configuration at startup to catch missing flags early."],"tags":["config","native-gateway","env-var"],"backgroundTag":"feature-not-enabled","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}