create-nextblock 0.9.71 → 0.9.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nextblock",
3
- "version": "0.9.71",
3
+ "version": "0.9.72",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,6 +1,9 @@
1
1
  import { draftMode } from "next/headers";
2
2
  import { NextRequest, NextResponse } from "next/server";
3
- import { normalizeDraftRedirectPath } from "../../../../lib/visual-editing/draft-route";
3
+ import {
4
+ normalizeDraftRedirectPath,
5
+ resolveRequestOrigin,
6
+ } from "../../../../lib/visual-editing/draft-route";
4
7
 
5
8
  export const runtime = "nodejs";
6
9
  export const dynamic = "force-dynamic";
@@ -19,7 +22,7 @@ export async function GET(request: NextRequest) {
19
22
  const draft = await draftMode();
20
23
  draft.disable();
21
24
 
22
- const response = NextResponse.redirect(new URL(normalizedPath, request.url));
25
+ const response = NextResponse.redirect(new URL(normalizedPath, resolveRequestOrigin(request)));
23
26
  response.headers.set("Cache-Control", "no-store");
24
27
  return response;
25
28
  }
@@ -4,6 +4,7 @@ import { createVerificationClient } from "../../../lib/visual-editing/draft-cont
4
4
  import {
5
5
  normalizeDraftRedirectPath,
6
6
  resolveDraftPathTarget,
7
+ resolveRequestOrigin,
7
8
  type DraftPathTarget,
8
9
  } from "../../../lib/visual-editing/draft-route";
9
10
 
@@ -87,7 +88,7 @@ export async function GET(request: NextRequest) {
87
88
  const draft = await draftMode();
88
89
  draft.enable();
89
90
 
90
- const response = NextResponse.redirect(new URL(target.path, request.url));
91
+ const response = NextResponse.redirect(new URL(target.path, resolveRequestOrigin(request)));
91
92
  response.headers.set("Cache-Control", "no-store");
92
93
  return response;
93
94
  }
@@ -4,6 +4,7 @@ import { getCurrentUserCanEdit } from "../../../../lib/visual-editing/draft-cont
4
4
  import {
5
5
  normalizeDraftRedirectPath,
6
6
  resolveDraftPathTarget,
7
+ resolveRequestOrigin,
7
8
  type DraftPathTarget,
8
9
  } from "../../../../lib/visual-editing/draft-route";
9
10
 
@@ -15,10 +16,11 @@ function getRequestedPath(request: NextRequest) {
15
16
  }
16
17
 
17
18
  function redirectToSignIn(request: NextRequest, normalizedPath: string) {
18
- const retryUrl = new URL(request.nextUrl.pathname, request.url);
19
+ const origin = resolveRequestOrigin(request);
20
+ const retryUrl = new URL(request.nextUrl.pathname, origin);
19
21
  retryUrl.searchParams.set("path", normalizedPath);
20
22
 
21
- const signInUrl = new URL("/sign-in", request.url);
23
+ const signInUrl = new URL("/sign-in", origin);
22
24
  signInUrl.searchParams.set("redirect", `${retryUrl.pathname}${retryUrl.search}`);
23
25
  return redirectNoStore(signInUrl);
24
26
  }
@@ -73,5 +75,5 @@ export async function GET(request: NextRequest) {
73
75
  const draft = await draftMode();
74
76
  draft.enable();
75
77
 
76
- return redirectNoStore(new URL(target.path, request.url));
78
+ return redirectNoStore(new URL(target.path, resolveRequestOrigin(request)));
77
79
  }
@@ -1,3 +1,4 @@
1
+ import type { NextRequest } from "next/server";
1
2
  import type { NextblockDocumentType } from "./types";
2
3
 
3
4
  export type DraftPathDocumentType = NextblockDocumentType | "product";
@@ -80,3 +81,20 @@ export function resolveDraftPathTarget(path: string): DraftPathTarget | null {
80
81
  path: `/${encodeURIComponent(slug)}`,
81
82
  };
82
83
  }
84
+
85
+ /**
86
+ * Browser-facing origin for a redirect. In the self-hosted Docker standalone server (binds to
87
+ * HOSTNAME=0.0.0.0), `request.url` / `request.nextUrl.origin` carry `http://0.0.0.0:3000` — an
88
+ * unroutable address that the browser rejects (ERR_ADDRESS_INVALID). The incoming `Host` header
89
+ * reflects what the user actually requested (e.g. localhost:3000), so prefer it (honoring
90
+ * `x-forwarded-proto` behind a proxy). Falls back to the request origin when no Host is present.
91
+ */
92
+ export function resolveRequestOrigin(request: NextRequest): string {
93
+ const host = request.headers.get("host");
94
+ if (host) {
95
+ const forwardedProto = request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
96
+ const protocol = forwardedProto || request.nextUrl.protocol.replace(/:$/, "") || "http";
97
+ return `${protocol}://${host}`;
98
+ }
99
+ return request.nextUrl.origin;
100
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextblock-cms/template",
3
- "version": "0.9.71",
3
+ "version": "0.9.72",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "next dev",