feat: improve handling of deployment env vars
These are now defined in Netlify UI for dedicated environments (test, stage, production): AUTH_URL NEXTAUTH_URL PUBLIC_URL Code now falls back to incoming request host. Mainly used for deployment previews which do not have Akamai in front, meaning we do not need the above workaround as incoming request host matches the actual public facing host. When Akamai is in front, we lose the public facing host in Netlify's routing layer as they internally use `x-forwarded-for` and we can't claim it for our usage.
This commit is contained in:
@@ -4,14 +4,17 @@ import { env } from "process"
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { profile } from "@/constants/routes/myPages"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
import { getPublicURL } from "@/server/utils"
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { lang: string } }
|
||||
) {
|
||||
const publicURL = getPublicURL(request)
|
||||
|
||||
console.log(`[add-card] callback started`)
|
||||
const lang = params.lang as Lang
|
||||
const returnUrl = new URL(`${env.PUBLIC_URL}/${profile[lang ?? Lang.en]}`)
|
||||
const returnUrl = new URL(`${publicURL}/${profile[lang ?? Lang.en]}`)
|
||||
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLIC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const runtime = "edge"
|
||||
@@ -1,39 +0,0 @@
|
||||
import { config } from "dotenv"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
config({ path: "./.env" })
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLIC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -1,38 +0,0 @@
|
||||
import "dotenv/config"
|
||||
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -1,39 +0,0 @@
|
||||
import { config } from "dotenv"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
config({ debug: true, override: true })
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -1,36 +0,0 @@
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLIC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -1,37 +0,0 @@
|
||||
import { config } from "dotenv"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
config({ path: "./.env" })
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLIC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import "dotenv/config"
|
||||
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLIC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import { config } from "dotenv"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
config({ debug: true, override: true })
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLIC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const e = process.env
|
||||
console.log({ process_env: process.env })
|
||||
|
||||
const urlVar = "PUBLIC_URL"
|
||||
const nextAuthUrlVar = "NEXTAUTH_URL"
|
||||
const nextAuthUrlVar2 = "AUTH_URL"
|
||||
const envTestVar = "ENVTEST"
|
||||
|
||||
const values = {
|
||||
env_url: env.PUBLIC_URL,
|
||||
static_url: process.env.PUBLIC_URL,
|
||||
dynamic_url: e[urlVar],
|
||||
env_envtest: env.ENVTEST,
|
||||
static_envtest: process.env.ENVTEST,
|
||||
dynamic_envtest: e[envTestVar],
|
||||
env_nextauth: env.NEXTAUTH_URL,
|
||||
static_nextauth: process.env.NEXTAUTH_URL,
|
||||
dynamic_nextauth: e[nextAuthUrlVar],
|
||||
env_nextauth2: env.AUTH_URL,
|
||||
static_nextauth2: process.env.AUTH_URL,
|
||||
dynamic_nextauth2: e[nextAuthUrlVar2],
|
||||
}
|
||||
|
||||
console.log(values)
|
||||
|
||||
return NextResponse.json(values)
|
||||
}
|
||||
@@ -6,20 +6,21 @@ import {
|
||||
bookingConfirmation,
|
||||
payment,
|
||||
} from "@/constants/routes/hotelReservation"
|
||||
import { getPublicURL } from "@/server/utils"
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { lang: string; status: string } }
|
||||
): Promise<NextResponse> {
|
||||
const publicURL = getPublicURL(request)
|
||||
|
||||
console.log(`[payment-callback] callback started`)
|
||||
const lang = params.lang as Lang
|
||||
const status = params.status
|
||||
const returnUrl = new URL(`${env.PUBLIC_URL}/${payment[lang]}`)
|
||||
const returnUrl = new URL(`${publicURL}/${payment[lang]}`)
|
||||
|
||||
if (status === "success") {
|
||||
const confirmationUrl = new URL(
|
||||
`${env.PUBLIC_URL}/${bookingConfirmation[lang]}`
|
||||
)
|
||||
const confirmationUrl = new URL(`${publicURL}/${bookingConfirmation[lang]}`)
|
||||
console.log(`[payment-callback] redirecting to: ${confirmationUrl}`)
|
||||
return NextResponse.redirect(confirmationUrl)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user