Skip to content

Commit

Permalink
[next] Fix API page check (#5196)
Browse files Browse the repository at this point in the history
This corrects the `isApiPage` check to not incorrectly detect `/api-docs` as an API route. 

Note: tests won't pass until a new canary with the below Next.js PR has been landed

x-ref: vercel/next.js#17092
Closes: vercel/next.js#17091
  • Loading branch information
ijjk authored Sep 15, 2020
1 parent 68225c5 commit dcd0276
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ export const build = async ({
};

const isApiPage = (page: string) =>
page.replace(/\\/g, '/').match(/serverless\/pages\/api/);
page.replace(/\\/g, '/').match(/serverless\/pages\/api(\/|\.js$)/);

const canUsePreviewMode = Object.keys(pages).some(page =>
isApiPage(pages[page].fsPath)
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/22-ssg-v2/now.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@
"path": "/_next/data/testing-build-id/nofallback/nope.json",
"status": 404
},
{
"path": "/api-docs/first",
"status": 200,
"mustContain": "API Docs"
},
{
"path": "/api-docs/second",
"status": 200,
"mustContain": "Loading..."
},
{
"path": "/_next/data/testing-build-id/api-docs/first.json",
"status": 200,
"responseHeaders": {
"x-vercel-cache": "/HIT|STALE|PRERENDER/"
}
},
{
"path": "/_next/data/testing-build-id/api-docs/second.json",
"status": 200
},
{
"logMustNotContain": "WARNING: your application is being opted out of @vercel/next's optimized lambdas mode due to legacy routes"
},
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/22-ssg-v2/pages/api-docs/[...slug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useRouter } from 'next/router';

export const getStaticProps = () => {
return {
props: {
hello: 'world',
},
};
};

export const getStaticPaths = () => {
return {
paths: ['/api-docs/first'],
fallback: true,
};
};

export default function Slug(props) {
if (useRouter().isFallback) return 'Loading...';

return (
<>
<p id="api-docs">API Docs</p>
<p id="props">{JSON.stringify(props)}</p>
</>
);
}

0 comments on commit dcd0276

Please sign in to comment.