File tree Expand file tree Collapse file tree
packages/next/src/shared/lib/page-path
test/integration/api-support/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { pathHasPrefix } from '../router/utils/path-has-prefix'
2+
13/**
24 * strip _next/data/<build-id>/ prefix and .json suffix
35 */
46export function normalizeDataPath ( pathname : string ) {
7+ if ( ! pathHasPrefix ( pathname || '/' , '/_next/data' ) ) {
8+ return pathname
9+ }
510 pathname = pathname
611 . replace ( / \/ _ n e x t \/ d a t a \/ [ ^ / ] { 1 , } / , '' )
712 . replace ( / \. j s o n $ / , '' )
Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ let mode
2525let app
2626
2727function runTests ( dev = false ) {
28+ it ( 'should not strip .json from API route' , async ( ) => {
29+ const res = await fetchViaHTTP ( appPort , '/api/hello.json' )
30+ expect ( res . status ) . toBe ( 200 )
31+ expect ( await res . json ( ) ) . toEqual ( { post : 'hello.json' } )
32+ } )
33+
2834 it ( 'should handle proxying to self correctly' , async ( ) => {
2935 const res1 = await fetchViaHTTP ( appPort , '/api/proxy-self' )
3036 expect ( res1 . status ) . toBe ( 200 )
You can’t perform that action at this time.
0 commit comments