nextjs api route request.url origin returns with domain assigned


I’m deploying nextjs to fly following this guide

App deploys and renders well using custom domain but;

I have an api endpoint (GET) where I access the request.url from params, this should return the request url with domain e.g. but I get This doesn’t happen on vercel deployments



  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ['app']

  memory = '512mb'
  cpu_kind = 'shared'
  cpus = 1


# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired


FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Next.js"

# Next.js app lives here


# Set production environment

ENV NODE_ENV="production"

# Install pnpm


RUN npm install -g pnpm@$PNPM_VERSION

# Throw-away build stage to reduce size of final image

FROM base as build

# Install packages needed to build node modules

RUN apt-get update -qq && \

apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3 ca-certificates

# Install node modules

COPY --link package.json pnpm-lock.yaml ./

RUN pnpm install --frozen-lockfile --prod=false

# Copy application code

COPY --link . .

# Build application

#docker secrets redacted

pnpm run build

# Remove development dependencies

RUN pnpm prune --prod

# Final stage for app image

FROM base

# Copy built application

COPY --from=build /app/.next/standalone /app

COPY --from=build /app/.next/static /app/.next/static

COPY --from=build /app/public /app/public

# Start the server by default, this can be overwritten at runtime



CMD [ "node", "server.js" ]

thanks in advance!

This is because Vercel is doing its own special sauce vs your standalone dockerized app. Same reason why you won’t have access to the fancy geo object. I believe you can find all the info in the request.headers object though.

Also, you should set ENV HOSTNAME :: so that your other fly apps can communicate w/ it.

1 Like

unfortunately headers doesn’t suffice my use-case :confused: I use supabase as BaaS their auth flow requires access to requestUrl.searchParams to get auth code, token and hash…

I remember this was working on other docker instances (e.g. railway/coolify) not sure why not on fly

Hmm are you sure it was working in other platforms? Because next standalone generates the server.js file which calls startServer({ hostname, ... }), where hostname is the HOSTNAME env, in this case it’s… so request.url will have as the hostname.

1 Like

yeah I figured others are not standalone builds but built with nixpack

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.