Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: add environment variable for ERP and MES urls

Brad Barbin1096f07e0c29
diff --git a/.env.example b/.env.example
index 1d5c5ad56d..89c25568a5 100644
--- a/.env.example
+++ b/.env.example
@@ -6,6 +6,9 @@ CLOUDFLARE_TURNSTILE_SECRET_KEY="********************"
DOMAIN="localhost:3000"
+ERP_URL="http://localhost:3000"
+MES_URL="http://localhost:3001"
+
NOVU_APPLICATION_ID="********************"
NOVU_SECRET_KEY="********************"
diff --git a/apps/academy/app/root.tsx b/apps/academy/app/root.tsx
index a6195c6427..0421133cb6 100644
--- a/apps/academy/app/root.tsx
+++ b/apps/academy/app/root.tsx
@@ -249,9 +249,11 @@ export default function App() {
<Document mode={mode} theme={theme}>
<header className="flex select-none items-center py-4 pl-5 pr-2 h-[var(--header-height)]">
<div className="max-w-5xl mx-auto px-4 flex items-center justify-between gap-2 z-logo text-foreground w-full">
- <Link
- to="/"
- className="cursor-pointer flex flex-row items-end gap-2 flex-shrink-0 font-display"
+ <a
+ href="https://app.carbon.ms"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="cursor-pointer inline-flex flex-row items-end gap-2 flex-shrink-0 font-display"
>
<img
src="/carbon-word-light.svg"
@@ -263,7 +265,7 @@ export default function App() {
alt="Carbon"
className="h-7 w-auto hidden dark:block"
/>
- </Link>
+ </a>
<div className="flex items-center">
<div className="items-center gap-1 hidden md:flex">
<Button variant="ghost" asChild>
diff --git a/apps/academy/app/utils/path.ts b/apps/academy/app/utils/path.ts
index d5cf3be6c5..dd20574b2e 100644
--- a/apps/academy/app/utils/path.ts
+++ b/apps/academy/app/utils/path.ts
@@ -1,4 +1,4 @@
-import { SUPABASE_URL } from "@carbon/auth";
+import { ERP_URL as ERP_URL_CONFIG, SUPABASE_URL } from "@carbon/auth";
import { generatePath } from "react-router";
const challenge = "/challenge"; // from ~/routes/challenge+ folder
@@ -7,7 +7,7 @@ const lesson = "/lesson"; // from ~/routes/lesson+ folder
const ERP_URL = SUPABASE_URL?.includes("localhost")
? "http://localhost:3000"
- : "https://app.carbon.ms";
+ : ERP_URL_CONFIG;
export const path = {
to: {
diff --git a/apps/erp/app/routes/api+/integrations.slack.interactive.ts b/apps/erp/app/routes/api+/integrations.slack.interactive.ts
index c4b0f118d9..4f9f917221 100644
--- a/apps/erp/app/routes/api+/integrations.slack.interactive.ts
+++ b/apps/erp/app/routes/api+/integrations.slack.interactive.ts
@@ -1,4 +1,4 @@
-import { getCarbonServiceRole } from "@carbon/auth";
+import { ERP_URL, getCarbonServiceRole } from "@carbon/auth";
import type { Database } from "@carbon/database";
import {
createIssueSlackThread,
@@ -442,7 +442,7 @@ async function handleViewSubmission(
createIssueSlackThread(
serviceRole,
{
- carbonUrl: `https://app.carbon.ms${path.to.issue(ncrId)}`,
+ carbonUrl: `${ERP_URL}${path.to.issue(ncrId)}`,
companyId,
description,
id: ncrId,
diff --git a/apps/erp/app/routes/x+/issue+/$id.status.tsx b/apps/erp/app/routes/x+/issue+/$id.status.tsx
index ead47ddf0c..7d24eecd40 100644
--- a/apps/erp/app/routes/x+/issue+/$id.status.tsx
+++ b/apps/erp/app/routes/x+/issue+/$id.status.tsx
@@ -1,4 +1,4 @@
-import { assertIsPost, error, success } from "@carbon/auth";
+import { assertIsPost, ERP_URL, error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { notifyIssueStatusChanged } from "@carbon/ee/notifications";
@@ -51,7 +51,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
await notifyIssueStatusChanged({ client }, integrations, {
companyId,
userId,
- carbonUrl: `https://app.carbon.ms${path.to.issue(id)}`, // We might need the full URL here
+ carbonUrl: `${ERP_URL}${path.to.issue(id)}`, // We might need the full URL here
issue: {
id,
status,
diff --git a/apps/erp/app/routes/x+/issue+/new.tsx b/apps/erp/app/routes/x+/issue+/new.tsx
index fada0acd3d..84aa320385 100644
--- a/apps/erp/app/routes/x+/issue+/new.tsx
+++ b/apps/erp/app/routes/x+/issue+/new.tsx
@@ -1,4 +1,9 @@
-import { assertIsPost, error, getCarbonServiceRole } from "@carbon/auth";
+import {
+ assertIsPost,
+ ERP_URL,
+ error,
+ getCarbonServiceRole
+} from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { notifyIssueCreated } from "@carbon/ee/notifications";
@@ -126,7 +131,7 @@ export async function action({ request }: ActionFunctionArgs) {
await notifyIssueCreated({ client, serviceRole }, integrations, {
companyId,
userId,
- carbonUrl: `https://app.carbon.ms${path.to.issue(ncrId)}`,
+ carbonUrl: `${ERP_URL}${path.to.issue(ncrId)}`,
issue: {
id: ncrId,
nonConformanceId: nextSequence.data,
diff --git a/apps/erp/app/routes/x+/issue+/task.$id.status.tsx b/apps/erp/app/routes/x+/issue+/task.$id.status.tsx
index b305c6d0b4..df75e1c8d8 100644
--- a/apps/erp/app/routes/x+/issue+/task.$id.status.tsx
+++ b/apps/erp/app/routes/x+/issue+/task.$id.status.tsx
@@ -1,4 +1,4 @@
-import { assertIsPost, error } from "@carbon/auth";
+import { assertIsPost, ERP_URL, error } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { notifyTaskStatusChanged } from "@carbon/ee/notifications";
@@ -51,9 +51,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
await notifyTaskStatusChanged({ client }, integrations, {
companyId,
userId,
- carbonUrl: `https://app.carbon.ms${path.to.issue(
- update.data.nonConformanceId
- )}`,
+ carbonUrl: `${ERP_URL}${path.to.issue(update.data.nonConformanceId)}`,
task: {
id,
status,
diff --git a/packages/auth/src/config/env.ts b/packages/auth/src/config/env.ts
index 266bc3cc1f..eaa0918f9d 100644
--- a/packages/auth/src/config/env.ts
+++ b/packages/auth/src/config/env.ts
@@ -7,6 +7,8 @@ declare global {
CARBON_EDITION: string;
CLOUDFLARE_TURNSTILE_SITE_KEY: string;
CONTROLLED_ENVIRONMENT: string;
+ ERP_URL: string;
+ MES_URL: string;
POSTHOG_API_HOST: string;
POSTHOG_PROJECT_PUBLIC_KEY: string;
SUPABASE_URL: string;
@@ -26,6 +28,8 @@ declare global {
CLOUDFLARE_TURNSTILE_SITE_KEY: string;
CLOUDFLARE_TURNSTILE_SECRET_KEY: string;
DOMAIN: string;
+ ERP_URL: string;
+ MES_URL: string;
NOVU_SECRET_KEY: string;
POSTHOG_API_HOST: string;
POSTHOG_PROJECT_PUBLIC_KEY: string;
@@ -125,6 +129,13 @@ export const EXCHANGE_RATES_API_KEY = getEnv("EXCHANGE_RATES_API_KEY", {
isSecret: true
});
+export const ERP_URL =
+ getEnv("ERP_URL", { isRequired: false, isSecret: false }) ??
+ "https://app.carbon.ms";
+export const MES_URL =
+ getEnv("MES_URL", { isRequired: false, isSecret: false }) ??
+ "https://mes.carbon.ms";
+
export const GOOGLE_PLACES_API_KEY = getEnv("GOOGLE_PLACES_API_KEY", {
isRequired: false
});
@@ -272,9 +283,11 @@ export const RATE_LIMIT = parseInt(
export function getAppUrl() {
if (VERCEL_ENV === "production" || NODE_ENV === "production") {
- return CONTROLLED_ENVIRONMENT
- ? "https://itar.carbon.ms"
- : "https://app.carbon.ms";
+ return ERP_URL
+ ? ERP_URL
+ : CONTROLLED_ENVIRONMENT
+ ? "https://itar.carbon.ms"
+ : "https://app.carbon.ms";
}
if (VERCEL_ENV === "preview") {
@@ -286,9 +299,11 @@ export function getAppUrl() {
export function getMESUrl() {
if (VERCEL_ENV === "production" || NODE_ENV === "production") {
- return CONTROLLED_ENVIRONMENT
- ? "https://mes.itar.carbon.ms"
- : "https://mes.carbon.ms";
+ return MES_URL
+ ? MES_URL
+ : CONTROLLED_ENVIRONMENT
+ ? "https://mes.itar.carbon.ms"
+ : "https://mes.carbon.ms";
}
if (VERCEL_ENV === "preview") {
diff --git a/packages/jobs/trigger/notify.ts b/packages/jobs/trigger/notify.ts
index effbae64e8..64c14fabfd 100644
--- a/packages/jobs/trigger/notify.ts
+++ b/packages/jobs/trigger/notify.ts
@@ -1,9 +1,9 @@
import {
getCarbonServiceRole,
+ ERP_URL,
NOVU_SECRET_KEY,
VERCEL_URL,
} from "@carbon/auth";
-
import type { Database } from "@carbon/database";
import { notifyTaskAssigned } from "@carbon/ee/notifications";
import {
@@ -538,7 +538,7 @@ export const notifyTask = task({
await notifyTaskAssigned({ client }, integrationsResult.data, {
companyId: payload.companyId,
userId: payload.from || "system",
- carbonUrl: `https://app.carbon.ms/x/issue/${payload.documentId}`,
+ carbonUrl: `${ERP_URL}/x/issue/${payload.documentId}`,
task: {
id: payload.documentId,
table: "nonConformance",
diff --git a/packages/jobs/trigger/weekly.ts b/packages/jobs/trigger/weekly.ts
index 6547ceab67..d622eecfc4 100644
--- a/packages/jobs/trigger/weekly.ts
+++ b/packages/jobs/trigger/weekly.ts
@@ -14,7 +14,7 @@ export const weekly = schedules.task({
console.log(`📅 Starting weekly tasks: ${new Date().toISOString()}`);
try {
- if (process.env.CARBON_EDITION === Edition.Cloud || true) {
+ if (process.env.CARBON_EDITION === Edition.Cloud) {
const bypassUrl = `${process.env.VERCEL_URL}/api/settings/bypass`;
const bypassResponse = await fetch(bypassUrl);
if (!bypassResponse.ok) {
diff --git a/packages/stripe/stripe.register.ts b/packages/stripe/stripe.register.ts
index c940da2a64..c9d04771c9 100644
--- a/packages/stripe/stripe.register.ts
+++ b/packages/stripe/stripe.register.ts
@@ -5,6 +5,7 @@ config();
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
const VERCEL_URL = process.env.VERCEL_URL;
+const ERP_URL = process.env.ERP_URL;
if (!STRIPE_SECRET_KEY) {
console.error("❌ STRIPE_SECRET_KEY is required");
@@ -44,7 +45,7 @@ const events: Stripe.WebhookEndpointCreateParams.EnabledEvent[] = [
];
// const webhookUrl = `https://${VERCEL_URL}/api/webhook/stripe`;
-const webhookUrl = `https://app.carbon.ms/api/webhook/stripe`;
+const webhookUrl = `${ERP_URL}/api/webhook/stripe`;
if (webhookUrl.includes("localhost")) {
throw new Error("Cannot register webhook in local development mode");
}
diff --git a/sst.config.ts b/sst.config.ts
index 417694e418..76d2ae818e 100644
--- a/sst.config.ts
+++ b/sst.config.ts
@@ -51,7 +51,9 @@ export default $config({
process.env.CLOUDFLARE_TURNSTILE_SITE_KEY,
CONTROLLED_ENVIRONMENT: process.env.CONTROLLED_ENVIRONMENT,
DOMAIN: "carbon.ms",
+ ERP_URL: "https://itar.carbon.ms",
EXCHANGE_RATES_API_KEY: process.env.EXCHANGE_RATES_API_KEY,
+ MES_URL: "https://mes.itar.carbon.ms",
NOVU_APPLICATION_ID: process.env.NOVU_APPLICATION_ID,
NOVU_SECRET_KEY: process.env.NOVU_SECRET_KEY,
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
@@ -141,7 +143,9 @@ export default $config({
process.env.CLOUDFLARE_TURNSTILE_SITE_KEY,
CONTROLLED_ENVIRONMENT: process.env.CONTROLLED_ENVIRONMENT,
DOMAIN: "carbon.ms",
+ ERP_URL: "https://itar.carbon.ms",
EXCHANGE_RATES_API_KEY: process.env.EXCHANGE_RATES_API_KEY,
+ MES_URL: "https://mes.itar.carbon.ms",
NOVU_APPLICATION_ID: process.env.NOVU_APPLICATION_ID,
NOVU_SECRET_KEY: process.env.NOVU_SECRET_KEY,
OPENAI_API_KEY: process.env.OPENAI_API_KEY,