Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

delong3
Copy link
Collaborator

@delong3 delong3 commented Oct 7, 2025

Improved environment variable configuration system

  • env file validation on boot
  • updated .env.example with more detailed information
  • more detailed error messages when env vars are invalid or outdated
  • partial migration of env var usages to config system

Summary by cubic

Centralized environment configuration with validation at startup to prevent misconfigurations, plus refactors to use a typed config across the API. This improves reliability, clearer errors, and safer defaults for self-hosted setups.

  • New Features

    • Added config.ts with Zod schema to parse and validate env vars on boot (fail-fast with helpful messages).
    • Updated .env.example with clearer docs, defaults, and new options (logging, ports, search/LLM providers).
    • Enforced BULL_AUTH_KEY format and added ALLOW_LOCAL_WEBHOOKS as a proper boolean.
    • Provider checks and messages for Serper, SearXNG, and Vertex credentials.
    • Unified Redis, rate limiter, proxy, and Bull Board paths via config.
    • Consistent self-hosted detection (isSelfHosted) used across controllers, workers, and webhooks.
  • Migration

    • Copy updates from apps/api/.env.example and ensure values match your setup.
    • Use WORKER_PORT for the queue worker and EXTRACT_WORKER_PORT for the extract worker.
    • Set PLAYWRIGHT_MICROSERVICE_URL if you use the Playwright service; leave empty otherwise.
    • If using Serper or SearXNG, set SERPER_API_KEY or SEARXNG_ENDPOINT (and optional engines/categories).
    • If using PostHog, set both POSTHOG_API_KEY and POSTHOG_HOST.
    • Only set ALLOW_LOCAL_WEBHOOKS if you trust local/internal webhook targets.
    • USE_DB_AUTHENTICATION defaults to false; enable only in cloud deployments with Supabase configured.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 43 files

Prompt for AI agents (all 5 issues)

Understand the root cause of the following 5 issues and fix them.


<file name="apps/api/.env.example">

<violation number="1" location="apps/api/.env.example:12">
`NUQ_DATABASE_URL`’s default points at port 5433, but the bundled Postgres service listens on 5432; with this default, the API cannot connect out of the box. Please align the example with the actual port.</violation>
</file>

<file name="apps/api/src/services/queue-worker.ts">

<violation number="1" location="apps/api/src/services/queue-worker.ts:309">
Binding the liveness server directly to config.WORKER_PORT ignores the platform-provided PORT fallback. Existing deployments that rely on only PORT (common on managed platforms) will now listen on the default 3005 and fail health checks. Please restore the PORT fallback when choosing the port.</violation>
</file>

<file name="apps/api/src/config.ts">

<violation number="1" location="apps/api/src/config.ts:34">
The boolean preprocessor turns every non-&quot;true&quot;/&quot;1&quot; value into false, so typos like ALLOW_LOCAL_WEBHOOKS=maybe pass validation silently instead of failing fast. Please return undefined for empty input, map known true/false strings, and leave other strings untouched so Zod can surface an explicit error.</violation>

<violation number="2" location="apps/api/src/config.ts:165">
Rule violated: **Enforce Use of Logger Instead of Console for Error Logging**

Replace the new `console.error` calls with the standard logger so production errors flow through the central logging pipeline [Rule: Enforce Use of Logger Instead of Console for Error Logging].</violation>
</file>

<file name="apps/api/src/lib/generic-ai.ts">

<violation number="1" location="apps/api/src/lib/generic-ai.ts:42">
Rule violated: **Enforce Use of Logger Instead of Console for Error Logging**

Replace this console.error call with the standard logger to comply with our logging policy for production error handling.</violation>
</file>


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

REDIS_RATE_LIMIT_URL=redis://redis:6379

# For self-hosting using docker, use postgres://postgres:postgres@nuq-postgres:5432/postgres. For running locally, use postgres://postgres:postgres@localhost:5433/postgres
NUQ_DATABASE_URL=postgres://postgres:postgres@nuq-postgres:5433/postgres
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NUQ_DATABASE_URL’s default points at port 5433, but the bundled Postgres service listens on 5432; with this default, the API cannot connect out of the box. Please align the example with the actual port.

Prompt for AI agents
Address the following comment on apps/api/.env.example at line 12:

<comment>`NUQ_DATABASE_URL`’s default points at port 5433, but the bundled Postgres service listens on 5432; with this default, the API cannot connect out of the box. Please align the example with the actual port.</comment>

<file context>
@@ -1,100 +1,141 @@
+REDIS_RATE_LIMIT_URL=redis://redis:6379
+
+# For self-hosting using docker, use postgres://postgres:postgres@nuq-postgres:5432/postgres. For running locally, use postgres://postgres:postgres@localhost:5433/postgres
+NUQ_DATABASE_URL=postgres://postgres:postgres@nuq-postgres:5433/postgres
+
+# For using the Playwright microservice, set the URL here (set to empty if you are not using Playwright)
</file context>
Suggested change
NUQ_DATABASE_URL=postgres://postgres:postgres@nuq-postgres:5433/postgres
NUQ_DATABASE_URL=postgres://postgres:postgres@nuq-postgres:5432/postgres

✅ Addressed in 60c1341

const workerPort = process.env.WORKER_PORT || process.env.PORT || 3005;
app.listen(workerPort, () => {
_logger.info(`Liveness endpoint is running on port ${workerPort}`);
app.listen(config.WORKER_PORT, () => {
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding the liveness server directly to config.WORKER_PORT ignores the platform-provided PORT fallback. Existing deployments that rely on only PORT (common on managed platforms) will now listen on the default 3005 and fail health checks. Please restore the PORT fallback when choosing the port.

Prompt for AI agents
Address the following comment on apps/api/src/services/queue-worker.ts at line 309:

<comment>Binding the liveness server directly to config.WORKER_PORT ignores the platform-provided PORT fallback. Existing deployments that rely on only PORT (common on managed platforms) will now listen on the default 3005 and fail health checks. Please restore the PORT fallback when choosing the port.</comment>

<file context>
@@ -312,9 +306,8 @@ app.get(&quot;/liveness&quot;, (req, res) =&gt; {
-const workerPort = process.env.WORKER_PORT || process.env.PORT || 3005;
-app.listen(workerPort, () =&gt; {
-  _logger.info(`Liveness endpoint is running on port ${workerPort}`);
+app.listen(config.WORKER_PORT, () =&gt; {
+  _logger.info(`Liveness endpoint is running on port ${config.WORKER_PORT}`);
 });
</file context>
Fix with Cubic

const strbool = (defaultValue: boolean) =>
z
.preprocess(
val => (val === "true" || val === "1" ? true : false),
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The boolean preprocessor turns every non-"true"/"1" value into false, so typos like ALLOW_LOCAL_WEBHOOKS=maybe pass validation silently instead of failing fast. Please return undefined for empty input, map known true/false strings, and leave other strings untouched so Zod can surface an explicit error.

Prompt for AI agents
Address the following comment on apps/api/src/config.ts at line 34:

<comment>The boolean preprocessor turns every non-&quot;true&quot;/&quot;1&quot; value into false, so typos like ALLOW_LOCAL_WEBHOOKS=maybe pass validation silently instead of failing fast. Please return undefined for empty input, map known true/false strings, and leave other strings untouched so Zod can surface an explicit error.</comment>

<file context>
@@ -0,0 +1,180 @@
+const strbool = (defaultValue: boolean) =&gt;
+  z
+    .preprocess(
+      val =&gt; (val === &quot;true&quot; || val === &quot;1&quot; ? true : false),
+      z.boolean(),
+    )
</file context>
Fix with Cubic

// }
} catch (err) {
if (err instanceof z.ZodError) {
console.error("Problems found with environment variables:");
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule violated: Enforce Use of Logger Instead of Console for Error Logging

Replace the new console.error calls with the standard logger so production errors flow through the central logging pipeline [Rule: Enforce Use of Logger Instead of Console for Error Logging].

Prompt for AI agents
Address the following comment on apps/api/src/config.ts at line 165:

<comment>Replace the new `console.error` calls with the standard logger so production errors flow through the central logging pipeline [Rule: Enforce Use of Logger Instead of Console for Error Logging].</comment>

<file context>
@@ -0,0 +1,180 @@
+  //   }
+} catch (err) {
+  if (err instanceof z.ZodError) {
+    console.error(&quot;Problems found with environment variables:&quot;);
+    for (const issue of err.issues) {
+      if (issue.path &amp;&amp; issue.path.length &gt; 0) {
</file context>

✅ Addressed in 60c1341

keyFile: vertexCredentials,
};
} else {
console.error(
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule violated: Enforce Use of Logger Instead of Console for Error Logging

Replace this console.error call with the standard logger to comply with our logging policy for production error handling.

Prompt for AI agents
Address the following comment on apps/api/src/lib/generic-ai.ts at line 42:

<comment>Replace this console.error call with the standard logger to comply with our logging policy for production error handling.</comment>

<file context>
@@ -18,46 +20,71 @@ type Provider =
+          keyFile: vertexCredentials,
+        };
+      } else {
+        console.error(
+          &quot;Failed to parse VERTEX_CREDENTIALS environment variable. It should be a base64-encoded JSON string or a valid file path. Failing back to default keyFile.&quot;,
+        );
</file context>

✅ Addressed in 8c7d9eb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.