File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
packages/next/src/shared/lib/page-path
test/integration/api-support/test Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { pathHasPrefix } from '../router/utils/path-has-prefix'
2
+
1
3
/**
2
4
* strip _next/data/<build-id>/ prefix and .json suffix
3
5
*/
4
6
export function normalizeDataPath ( pathname : string ) {
7
+ if ( ! pathHasPrefix ( pathname || '/' , '/_next/data' ) ) {
8
+ return pathname
9
+ }
5
10
pathname = pathname
6
11
. replace ( / \/ _ n e x t \/ d a t a \/ [ ^ / ] { 1 , } / , '' )
7
12
. replace ( / \. j s o n $ / , '' )
Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ let mode
25
25
let app
26
26
27
27
function 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
+
28
34
it ( 'should handle proxying to self correctly' , async ( ) => {
29
35
const res1 = await fetchViaHTTP ( appPort , '/api/proxy-self' )
30
36
expect ( res1 . status ) . toBe ( 200 )
You can’t perform that action at this time.
0 commit comments