next.js/test/e2e/app-dir/cache-components/app/routes/fetch-mixed/route.ts
route.ts31 lines809 B
import type { NextRequest } from 'next/server'

import { getSentinelValue } from '../../getSentinelValue'

export async function GET(request: NextRequest) {
  const fetcheda = await fetchRandomCached('a')
  const fetchedb = await fetchRandomUncached('b')
  return new Response(
    JSON.stringify({
      value: getSentinelValue(),
      random1: fetcheda,
      random2: fetchedb,
    })
  )
}

const fetchRandomCached = async (entropy: string) => {
  const response = await fetch(
    'https://next-data-api-endpoint.vercel.app/api/random?b=' + entropy,
    { cache: 'force-cache' }
  )
  return response.text()
}

const fetchRandomUncached = async (entropy: string) => {
  const response = await fetch(
    'https://next-data-api-endpoint.vercel.app/api/random?b=' + entropy
  )
  return response.text()
}
Quest for Codev2.0.0
/
SIGN IN