File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed
app/api/stripe/create-checkout-session Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ NEXT_PUBLIC_STRIPE_PRICE_ADS_FREE=price_...
1414NEXT_PUBLIC_STRIPE_PRICE_BYOK = price_...
1515NEXT_PUBLIC_STRIPE_PRICE_DITECTREV = price_...
1616NEXT_PUBLIC_STRIPE_PRICE_LOCAL = price_...
17- NEXT_PUBLIC_STRIPE_SECRET_KEY =
17+ STRIPE_SECRET_KEY =
1818
1919# AI Provider Keys (for Ditectrev premium service)
2020DITECTREV_OPENAI_KEY = sk-...
Original file line number Diff line number Diff line change 3232 # Stripe Configuration
3333 # Note: Using NEXT_PUBLIC_ prefix is required for Azure Static Web Apps runtime access
3434 # This is safe because it's only used in server-side API routes, never in client components
35- NEXT_PUBLIC_STRIPE_SECRET_KEY : ${{ secrets.NEXT_PUBLIC_STRIPE_SECRET_KEY }}
35+ NEXT_PUBLIC_STRIPE_SECRET_KEY : ${{ secrets.STRIPE_SECRET_KEY }}
3636 # Stripe Price IDs (environment variables, distinguished per environment)
3737 NEXT_PUBLIC_STRIPE_PRICE_ADS_FREE : ${{ vars.NEXT_PUBLIC_STRIPE_PRICE_ADS_FREE }}
3838 NEXT_PUBLIC_STRIPE_PRICE_LOCAL : ${{ vars.NEXT_PUBLIC_STRIPE_PRICE_LOCAL }}
Original file line number Diff line number Diff line change @@ -44,8 +44,33 @@ export async function POST(request: NextRequest) {
4444 apiVersion : "2025-11-17.clover" ,
4545 } ) ;
4646
47- // Get the base URL for redirects (always use dynamic URL for Azure Static Web Apps)
48- const baseUrl = `${ request . nextUrl . protocol } //${ request . nextUrl . host } ` ;
47+ // Get the base URL for redirects
48+ // Azure Static Web Apps may use internal hostnames, so we need to check headers
49+ const forwardedHost = request . headers . get ( "x-forwarded-host" ) ;
50+ const forwardedProto = request . headers . get ( "x-forwarded-proto" ) || "https" ;
51+ const referer = request . headers . get ( "referer" ) ;
52+
53+ let baseUrl : string ;
54+
55+ if ( forwardedHost ) {
56+ // Use forwarded host from Azure Static Web Apps
57+ baseUrl = `${ forwardedProto } ://${ forwardedHost } ` ;
58+ } else if ( referer ) {
59+ // Fallback to referer URL
60+ try {
61+ const refererUrl = new URL ( referer ) ;
62+ baseUrl = `${ refererUrl . protocol } //${ refererUrl . host } ` ;
63+ } catch {
64+ // If referer parsing fails, use the request URL
65+ baseUrl = `${ request . nextUrl . protocol } //${ request . nextUrl . host } ` ;
66+ }
67+ } else {
68+ // Last resort: use request URL (may be internal hostname)
69+ baseUrl = `${ request . nextUrl . protocol } //${ request . nextUrl . host } ` ;
70+ }
71+
72+ // Log for debugging
73+ console . log ( "Base URL for Stripe redirects:" , baseUrl ) ;
4974
5075 // Create Stripe checkout session
5176 const session = await stripe . checkout . sessions . create ( {
You can’t perform that action at this time.
0 commit comments