Unverified Commit 1e2c3792 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix API stripping JSON incorrectly (#82062)

Backports API stripping JSON fix to 15.4 branch

x-ref: https://github.com/vercel/next.js/pull/82061
parent fe5db658
import { pathHasPrefix } from '../router/utils/path-has-prefix'
/**
* strip _next/data/<build-id>/ prefix and .json suffix
*/
export function normalizeDataPath(pathname: string) {
if (!pathHasPrefix(pathname || '/', '/_next/data')) {
return pathname
}
pathname = pathname
.replace(/\/_next\/data\/[^/]{1,}/, '')
.replace(/\.json$/, '')
......
......@@ -25,6 +25,12 @@ let mode
let app
function runTests(dev = false) {
it('should not strip .json from API route', async () => {
const res = await fetchViaHTTP(appPort, '/api/hello.json')
expect(res.status).toBe(200)
expect(await res.json()).toEqual({ post: 'hello.json' })
})
it('should handle proxying to self correctly', async () => {
const res1 = await fetchViaHTTP(appPort, '/api/proxy-self')
expect(res1.status).toBe(200)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment