Openstatus www.openstatus.dev

yeah bebi

+17 -15
+17 -15
apps/status-page/src/middleware.ts
··· 77 77 if (_page.customDomain && host !== `${_page.slug}.stpg.dev`) { 78 78 const redirect = pathname.replace(`/${_page.customDomain}`, ""); 79 79 const url = new URL( 80 - `https://${ 81 - _page.customDomain 80 + `https://${_page.customDomain 82 81 }/protected?redirect=${encodeURIComponent(redirect)}`, 83 82 ); 84 83 console.log("redirect to /protected", url.toString()); ··· 86 85 } 87 86 88 87 const url = new URL( 89 - `${origin}${ 90 - type === "pathname" ? `/${prefix}` : "" 88 + `${origin}${type === "pathname" ? `/${prefix}` : "" 91 89 }/protected?redirect=${encodeURIComponent(pathname)}`, 92 90 ); 93 91 return NextResponse.redirect(url); ··· 104 102 105 103 return NextResponse.redirect( 106 104 new URL( 107 - `${req.nextUrl.origin}${ 108 - redirect ?? type === "pathname" ? `/${prefix}` : "/" 105 + `${req.nextUrl.origin}${redirect ?? type === "pathname" ? `/${prefix}` : "/" 109 106 }`, 110 107 ), 111 108 ); ··· 122 119 return NextResponse.rewrite(rewriteUrl); 123 120 } 124 121 125 - console.log({customDomain: _page.customDomain, host, expectedHost: `${_page.slug}.stpg.dev`}) 122 + console.log({ customDomain: _page.customDomain, host, expectedHost: `${_page.slug}.stpg.dev` }) 126 123 if (_page.customDomain && host !== `${_page.slug}.stpg.dev`) { 127 124 if (pathnames.length > 2 && !subdomain) { 128 125 const pathname = pathnames.slice(2).join("/"); ··· 145 142 rewriteUrl.search = url.search; 146 143 return NextResponse.rewrite(rewriteUrl); 147 144 } 148 - const rewriteUrl = new URL( 149 - `${url.pathname}`, 150 - `https://${_page.slug}.stpg.dev`, 151 - ); 152 - console.log({ rewriteUrl }); 153 - rewriteUrl.search = url.search; 154 - return NextResponse.rewrite(rewriteUrl); 145 + const rewriteUrl = new URL( 146 + `${url.pathname}`, 147 + `https://${_page.slug}.stpg.dev`, 148 + ); 149 + console.log({ rewriteUrl }); 150 + rewriteUrl.search = url.search; 151 + return NextResponse.rewrite(rewriteUrl); 155 152 156 153 157 154 } ··· 160 157 rewriteUrl.search = url.search; 161 158 return NextResponse.rewrite(rewriteUrl); 162 159 } 163 - 160 + if (host?.includes("openstatus.dev")){ 161 + const rewriteUrl = new URL(`/${prefix}${url.pathname}`, req.url); 162 + // Preserve search params from original request 163 + rewriteUrl.search = url.search; 164 + return NextResponse.rewrite(rewriteUrl); 165 + } 164 166 return response; 165 167 } 166 168