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.

feat: vercel edge runtime

Brad Barbin243e833d8c3e
diff --git a/apps/carbon/app/root.tsx b/apps/carbon/app/root.tsx
index 414d393677..8416d0eb99 100644
--- a/apps/carbon/app/root.tsx
+++ b/apps/carbon/app/root.tsx
@@ -27,6 +27,7 @@ import { error } from "~/utils/result";
import { useMode } from "./hooks/useMode";
import { getSessionFlash } from "./services/session.server";
import { modeValidator } from "./types/validators";
+import { parseVercelId } from "./utils/http";
export function links() {
return [
@@ -37,6 +38,8 @@ export function links() {
];
}
+export const config = { runtime: "edge" };
+
export const meta: MetaFunction = () => {
return [
{
@@ -54,6 +57,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
} = getBrowserEnv();
const sessionFlash = await getSessionFlash(request);
+ const { computeRegion, proxyRegion } = parseVercelId(
+ request.headers.get("x-vercel-id")
+ );
+
+ console.log({
+ computeRegion,
+ proxyRegion,
+ });
return json(
{
diff --git a/apps/carbon/app/utils/http.ts b/apps/carbon/app/utils/http.ts
index 02ce3e1844..56d9d06a36 100644
--- a/apps/carbon/app/utils/http.ts
+++ b/apps/carbon/app/utils/http.ts
@@ -113,3 +113,14 @@ export function parseNumberFromUrlParam(
return parsed;
}
+
+export function parseVercelId(id: string | null) {
+ const parts = id?.split(":").filter(Boolean);
+ if (!parts) {
+ console.log('"x-vercel-id" header not present. Running on localhost?');
+ return { proxyRegion: "localhost", computeRegion: "localhost" };
+ }
+ const proxyRegion = parts[0];
+ const computeRegion = parts[parts.length - 2];
+ return { proxyRegion, computeRegion };
+}