Progmasoft Git

progmaweb

The site and account service of Progmasoft: a Next.js frontend and an ASP.NET Core API.

Clonegit clone https://git.progmasoft.com/progmaweb

Let the second proxy pass through a site's own tree

The standalone server, which production runs, invokes the proxy again for
the rewritten path with the original host. A path already inside the
site's internal tree (/authorize/signin on authorize.progmasoft.com) did
not match the public routes and became the site's not-found page, so
every OAuth, console and product page answered 404 in production while
next start, which runs the proxy once, served them. A path under the
site's own root now passes unchanged; internal trees stay closed on every
other host. Checked against the standalone build for all hosts.
Commit
85bdf1aba26641bf90da84fd6ce642ac41a6e73e
Author
Leitwolf11 ·
Parents
6e871a697f64

Files · Download .tar.gz

Changes

 apps/web/proxy.ts | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/apps/web/proxy.ts b/apps/web/proxy.ts
index dd47981..2842e4c 100644
--- a/apps/web/proxy.ts
+++ b/apps/web/proxy.ts
@@ -99,6 +99,11 @@ export function proxy(request: NextRequest) {
     if (site.api && pathname.startsWith("/api/")) {
       return NextResponse.next();
     }
+    // The standalone server runs this proxy a second time for the rewritten
+    // path, with the same host: a path already in the site's tree is final.
+    if (pathname === site.root || pathname.startsWith(`${site.root}/`)) {
+      return NextResponse.next();
+    }
     const destination = internalRoute(
       request,
       site.route(pathname) ?? `${site.root}/not-found`,
@@ -108,6 +113,7 @@ export function proxy(request: NextRequest) {
     destination.search = request.nextUrl.search;
     return NextResponse.rewrite(destination);
   }
+  // The internal trees belong to their hosts only.
   for (const { root } of ownSites) {
     if (pathname === root || pathname.startsWith(`${root}/`)) {
       return NextResponse.rewrite(internalRoute(request, "/not-found"));