Skip to content

feat: add reverse-proxy-prefix option to build#616

Merged
jwartofsky-yext merged 14 commits into
mainfrom
reverseProxyOverwriteRepo
Jun 10, 2026
Merged

feat: add reverse-proxy-prefix option to build#616
jwartofsky-yext merged 14 commits into
mainfrom
reverseProxyOverwriteRepo

Conversation

@jwartofsky-yext

@jwartofsky-yext jwartofsky-yext commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

After running "npm run build -- --reverse-proxy-prefix=www.brand.com/locations", I see these files modified:

vite.config.ts

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import yextSSG from "@yext/pages/vite-plugin";
import { yextVisualEditorPlugin } from "@yext/visual-editor/plugin"

export default defineConfig({
    plugins: [react(), yextVisualEditorPlugin(), yextSSG()],
    build: {
        assetsDir: "locations/assets"
    }
});

config.yaml

buildConfiguration:
  buildCommand: npm run build
  installDependenciesStep:
    command: npm install
    requiredFiles:
      - package.json
      - package-lock.json
      - .npmrc
livePreviewConfiguration:
  setupCommand: ":"
sitemap:
  excludeList:
    - edit
serving:
  reverseProxyPrefix: www.brand.com/locations
dynamicRoutes:
  - from: /assets/*
    to: /locations/assets/:splat
    status: 200

The dist/assets are also updated:
image

See example of a run here: YextSolutions/pages-visual-editor-starter#330

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds build-time reverse proxy prefix support: a parser that validates/normalizes a host/subpath prefix, computes an assetsDir and a /assets/* dynamic route, updates scoped config.yaml (serving.reverseProxyPrefix and dynamicRoutes) and scoped vite.config.js (build.assetsDir), extends ProjectStructure to resolve scoped/unscoped vite config paths, adds tests, and wires a --reverse-proxy-prefix CLI option that triggers applyReverseProxyOverride during build.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Handler
  participant Apply as applyReverseProxyOverride
  participant Config as updateConfigYaml
  participant ViteCfg as updateViteConfig
  participant Vite as ViteBuild

  CLI->>Handler: invoke build with reverseProxyPrefix
  Handler->>Apply: call applyReverseProxyOverride(scope, prefix)
  Apply->>Config: update config.yaml (serving.reverseProxyPrefix + dynamicRoutes)
  Apply->>ViteCfg: update vite.config.js (build.assetsDir)
  Handler->>Vite: run Vite build (after override applied)
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add reverse-proxy-prefix option to build' directly and clearly describes the main change: adding a new CLI option for reverse proxy prefix configuration to the build command.
Description check ✅ Passed The description provides concrete examples of the feature's effect, showing how running the build with --reverse-proxy-prefix flag modifies vite.config.ts and config.yaml, and reorganizes dist/assets output.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch reverseProxyOverwriteRepo

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/pages/src/util/reverseProxyBuildOverride.test.ts (1)

12-48: ⚡ Quick win

Add parser regression tests for protocol/trailing-slash/invalid-character inputs.

Coverage is solid, but the parser should also be pinned for common edge inputs that directly affect both YAML and Vite rewrites.

Suggested additions
 describe("parseReverseProxyBuildOverride", () => {
+  it("accepts protocol-prefixed values and derives the same subpath outputs", () => {
+    expect(parseReverseProxyBuildOverride("https://www.brand.com/locations")).toEqual({
+      reverseProxyPrefix: "https://www.brand.com/locations",
+      assetsDir: "locations/assets",
+      dynamicRoute: {
+        from: "/assets/*",
+        to: "/locations/assets/:splat",
+        status: 200,
+      },
+    });
+  });
+
+  it("normalizes trailing slashes in subpath", () => {
+    expect(parseReverseProxyBuildOverride("www.brand.com/locations/")).toEqual({
+      reverseProxyPrefix: "www.brand.com/locations/",
+      assetsDir: "locations/assets",
+      dynamicRoute: {
+        from: "/assets/*",
+        to: "/locations/assets/:splat",
+        status: 200,
+      },
+    });
+  });
+
+  it("throws when subpath contains unsupported characters", () => {
+    expect(() => parseReverseProxyBuildOverride('www.brand.com/loca"tions')).toThrow();
+  });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/pages/src/util/reverseProxyBuildOverride.test.ts` around lines 12 -
48, The test suite for parseReverseProxyBuildOverride is missing regression
cases for inputs containing URL protocols, trailing slashes, and invalid
characters; add unit tests in reverseProxyBuildOverride.test.ts that call
parseReverseProxyBuildOverride with strings like "https://www.brand.com/foo",
"www.brand.com/foo/", and inputs containing illegal characters and assert the
expected behavior (either specific thrown error messages or normalized outputs)
so the parser is pinned for YAML/Vite rewrite consumers; reference the existing
tests for structure and assert messages matching the parser's validation (use
parseReverseProxyBuildOverride as the target function and check for throws on
protocol/trailing-slash/invalid-character cases).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/pages/src/util/reverseProxyBuildOverride.ts`:
- Around line 24-43: The current parsing of reverseProxyPrefix incorrectly
treats full URLs and unsafe characters as the subpath; update the parsing logic
that derives subpath (used to compute assetsDir and dynamicRoute.to) to first
detect and strip any URL scheme/host (e.g., if reverseProxyPrefix contains "://"
or looks like a host/path use URL parsing), then normalize the path by removing
leading/trailing slashes and collapsing duplicate slashes, validate/sanitize
characters (restrict to safe characters like alphanumerics, -, _, and / or
percent-decode then validate) and throw a clear Error if the resulting subpath
is empty or contains invalid chars; finally use that normalized subpath when
creating assetsDir and dynamicRoute.to/from so assetsDir and the routing targets
are safe and correct.

---

Nitpick comments:
In `@packages/pages/src/util/reverseProxyBuildOverride.test.ts`:
- Around line 12-48: The test suite for parseReverseProxyBuildOverride is
missing regression cases for inputs containing URL protocols, trailing slashes,
and invalid characters; add unit tests in reverseProxyBuildOverride.test.ts that
call parseReverseProxyBuildOverride with strings like
"https://www.brand.com/foo", "www.brand.com/foo/", and inputs containing illegal
characters and assert the expected behavior (either specific thrown error
messages or normalized outputs) so the parser is pinned for YAML/Vite rewrite
consumers; reference the existing tests for structure and assert messages
matching the parser's validation (use parseReverseProxyBuildOverride as the
target function and check for throws on
protocol/trailing-slash/invalid-character cases).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ffc6c3bf-247f-4059-9468-9860485ec86a

📥 Commits

Reviewing files that changed from the base of the PR and between 8ba6b60 and cb486c6.

📒 Files selected for processing (4)
  • packages/pages/src/build/build.ts
  • packages/pages/src/prod/prod.ts
  • packages/pages/src/util/reverseProxyBuildOverride.test.ts
  • packages/pages/src/util/reverseProxyBuildOverride.ts

Comment thread packages/pages/src/util/reverseProxyOverride.ts Outdated
@jwartofsky-yext jwartofsky-yext changed the title feat: add reverseProxyPrefix option to build feat: add reverse-proxy-prefix option to build Jun 8, 2026
@jwartofsky-yext jwartofsky-yext marked this pull request as ready for review June 8, 2026 21:26
@jwartofsky-yext jwartofsky-yext requested a review from a team as a code owner June 8, 2026 21:26
Comment thread packages/pages/src/prod/prod.ts Outdated
Comment thread packages/pages/src/util/reverseProxyOverride.ts Outdated
Comment thread packages/pages/src/prod/prod.ts Outdated
Comment thread packages/pages/src/util/reverseProxyOverride.ts Outdated
Comment thread packages/pages/src/util/reverseProxyOverride.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/pages/src/util/reverseProxyOverride.ts (1)

75-77: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Return the trimmed prefix for consistency.

The function returns the original reverseProxyPrefix (with potential leading/trailing whitespace) while assetsDir and dynamicRoute are computed from the trimmed version. This inconsistency could cause mismatches between the stored serving.reverseProxyPrefix in config.yaml and the actual asset paths.

Proposed fix
   return {
-    reverseProxyPrefix,
+    reverseProxyPrefix: trimmedReverseProxyPrefix,
     assetsDir: `${subpath}/assets`,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/pages/src/util/reverseProxyOverride.ts` around lines 75 - 77, The
returned reverseProxyPrefix value is not trimmed while assetsDir and
dynamicRoute are derived from the trimmed subpath; update the return to use the
trimmed prefix (the same value used to compute subpath/dynamicRoute) so
serving.reverseProxyPrefix matches asset paths — locate the reverseProxyOverride
function and replace the untrimmed reverseProxyPrefix in the returned object
with the trimmed variable (the same one used when computing assetsDir and
dynamicRoute) to ensure consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/pages/src/util/reverseProxyOverride.test.ts`:
- Line 12: Update the test suite description to match the actual function under
test: change the describe block currently named "parseReverseProxyOverride" so
it references buildReverseProxyOverride (the function being tested) to avoid
confusion; locate the describe(...) that wraps tests for
buildReverseProxyOverride in reverseProxyOverride.test.ts and rename its string
to "buildReverseProxyOverride".

---

Duplicate comments:
In `@packages/pages/src/util/reverseProxyOverride.ts`:
- Around line 75-77: The returned reverseProxyPrefix value is not trimmed while
assetsDir and dynamicRoute are derived from the trimmed subpath; update the
return to use the trimmed prefix (the same value used to compute
subpath/dynamicRoute) so serving.reverseProxyPrefix matches asset paths — locate
the reverseProxyOverride function and replace the untrimmed reverseProxyPrefix
in the returned object with the trimmed variable (the same one used when
computing assetsDir and dynamicRoute) to ensure consistency.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4cb49c42-9fb9-48c9-bfbd-eba3661a46e2

📥 Commits

Reviewing files that changed from the base of the PR and between cb486c6 and 08d856e.

📒 Files selected for processing (6)
  • packages/pages/src/build/build.ts
  • packages/pages/src/common/src/project/paths.ts
  • packages/pages/src/common/src/project/structure.ts
  • packages/pages/src/util/reverseProxyOverride.test.ts
  • packages/pages/src/util/reverseProxyOverride.ts
  • packages/pages/src/util/viteConfig.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/pages/src/common/src/project/paths.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/pages/src/build/build.ts

Comment thread packages/pages/src/util/reverseProxyOverride.test.ts Outdated
Comment thread packages/pages/src/common/src/project/structure.ts Outdated
Comment thread packages/pages/src/common/src/project/paths.ts Outdated
Comment thread packages/pages/src/util/reverseProxyOverride.ts Outdated
Comment thread packages/pages/src/util/reverseProxyOverride.ts Outdated
Comment thread packages/pages/src/util/viteConfig.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/pages/src/util/reverseProxyOverride.ts (1)

87-95: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the same Vite config resolver as the build command.

This helper always targets vite.config.js, but the build path later comes from scopedViteConfigPath(scope), and the PR objective/example repo uses vite.config.ts. In that case, --reverse-proxy-prefix will fail here even though the build has a valid Vite config.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/pages/src/util/reverseProxyOverride.ts` around lines 87 - 95, The
existence check currently hardcodes "vite.config.js" via viteConfigPath, which
can miss other resolved configs (e.g. vite.config.ts); change the logic to use
the same resolver used by the build by calling scopedViteConfigPath(scope) (the
same symbol used later) to compute the Vite config path and check that file
exists before applying reverseProxyPrefix, leaving configYamlPath checks as-is
and updating the thrown error message to reference the resolved path variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/pages/src/util/reverseProxyOverride.ts`:
- Around line 21-23: The function buildReverseProxyOverride currently trims
input into trimmedReverseProxyPrefix but later persists the original
reverseProxyPrefix into the config; update the persistence to use
trimmedReverseProxyPrefix instead so the written serving.reverseProxyPrefix
matches derived values (subpath, assetsDir, dynamic route). Locate
buildReverseProxyOverride and replace any uses that write reverseProxyPrefix
back to config.yaml (the save/persist step) with trimmedReverseProxyPrefix,
ensuring all derived fields (subpath, assetsDir, dynamic route) and the
persisted serving.reverseProxyPrefix are computed from the same trimmed value.

---

Outside diff comments:
In `@packages/pages/src/util/reverseProxyOverride.ts`:
- Around line 87-95: The existence check currently hardcodes "vite.config.js"
via viteConfigPath, which can miss other resolved configs (e.g. vite.config.ts);
change the logic to use the same resolver used by the build by calling
scopedViteConfigPath(scope) (the same symbol used later) to compute the Vite
config path and check that file exists before applying reverseProxyPrefix,
leaving configYamlPath checks as-is and updating the thrown error message to
reference the resolved path variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c7fc3ce5-0a02-4227-83cc-0a55e06e37dd

📥 Commits

Reviewing files that changed from the base of the PR and between 08d856e and 855f650.

📒 Files selected for processing (2)
  • packages/pages/src/util/reverseProxyOverride.test.ts
  • packages/pages/src/util/reverseProxyOverride.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/pages/src/util/reverseProxyOverride.test.ts

Comment thread packages/pages/src/util/reverseProxyOverride.ts
Comment thread packages/pages/src/util/reverseProxyOverride.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/pages/src/common/src/project/structure.ts`:
- Around line 221-224: The init() logic currently falls back to root
vite.config.js when a scoped file is missing, but getViteConfigPath() always
returns the scoped path; to make behavior consistent fail fast: in init() (where
viteConfigPath is computed) detect when config.scope is set and the resolved
scoped path (pathLib.resolve(config.scope ?? "", config.rootFiles.viteConfig))
does not exist, and throw/return an error instead of falling back to root;
update any callers expecting init() to succeed to handle the new error and keep
getViteConfigPath() unchanged (references: init(), getViteConfigPath(),
viteConfigPath, config.scope, config.rootFiles.viteConfig,
applyReverseProxyOverride).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8613bc80-675a-42ed-8c80-bc2303b5530c

📥 Commits

Reviewing files that changed from the base of the PR and between af05681 and 1c5b30e.

📒 Files selected for processing (4)
  • packages/pages/src/build/build.ts
  • packages/pages/src/common/src/project/structure.ts
  • packages/pages/src/util/reverseProxyOverride.test.ts
  • packages/pages/src/util/reverseProxyOverride.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/pages/src/build/build.ts
  • packages/pages/src/util/reverseProxyOverride.ts
  • packages/pages/src/util/reverseProxyOverride.test.ts

Comment thread packages/pages/src/common/src/project/structure.ts Outdated
Comment thread packages/pages/src/common/src/project/structure.ts
Comment thread packages/pages/src/common/src/project/structure.ts
Comment thread packages/pages/src/util/viteConfig.ts
@jwartofsky-yext jwartofsky-yext merged commit 118eae1 into main Jun 10, 2026
31 checks passed
@jwartofsky-yext jwartofsky-yext deleted the reverseProxyOverwriteRepo branch June 10, 2026 18:48
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.

4 participants