Skip to content

Commit 632d24b

Browse files
committed
easy
1 parent ba1dd1a commit 632d24b

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/middleware.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { NextResponse, type NextRequest } from "next/server";
2-
import { serverEnv } from "./utils/env/server";
2+
import { SERVER_URL_KEY } from "./utils/constants";
33

44
/**
55
* Nextjs bypass to set the server URL in the request headers so it can be read while in server components.
66
*/
77
export default async function middleware(request: NextRequest) {
88
const headers = new Headers(request.headers);
9-
headers.set(serverEnv.SERVER_URL_KEY, request.url);
9+
headers.set(SERVER_URL_KEY, request.url);
1010
return NextResponse.next({ headers });
1111
}
1212

1313
export const config = {
1414
matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"],
15-
unstable_allowDynamic: ["/node_modules/elysia/dist/index.mjs"],
1615
};

src/utils/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Note: bug in nodejs cant import serverEnv into middleware.ts
2+
export const SERVER_URL_KEY = "x-url";

src/utils/env/server/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SERVER_URL_KEY } from "@/utils/constants";
12
import { Elysia, t } from "elysia";
23

34
const {
@@ -13,7 +14,7 @@ const {
1314
},
1415
),
1516
AUTH_COOKIE: t.Literal("auth", { error: "AUTH_COOKIE not set!" }),
16-
SERVER_URL_KEY: t.Literal("x-url", { error: "SERVER_URL not set!" }),
17+
SERVER_URL_KEY: t.Literal(SERVER_URL_KEY, { error: "SERVER_URL not set!" }),
1718
SEVEN_DAYS: t.Integer({ minimum: 1, error: "SEVEN_DAYS not set!" }),
1819
}),
1920
});
@@ -23,7 +24,7 @@ const serverEnvResult = serverSchema.safeParse({
2324
SECRET: process.env.SECRET,
2425
NODE_ENV: process.env.NODE_ENV,
2526
AUTH_COOKIE: "auth",
26-
SERVER_URL_KEY: "x-url",
27+
SERVER_URL_KEY,
2728
SEVEN_DAYS: 60 * 60 * 24 * 7, // 7 days in seconds
2829
});
2930

0 commit comments

Comments
 (0)