File tree 2 files changed +11
-6
lines changed
packages/runtime/src/helpers
2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -337,11 +337,13 @@ const getServerFile = (root: string, includeBase = true) => {
337
337
/**
338
338
* Find the source file for a given page route
339
339
*/
340
- export const getSourceFileForPage = ( page : string , root : string ) => {
341
- for ( const extension of SOURCE_FILE_EXTENSIONS ) {
342
- const file = join ( root , `${ page } .${ extension } ` )
343
- if ( existsSync ( file ) ) {
344
- return file
340
+ export const getSourceFileForPage = ( page : string , roots : string [ ] ) => {
341
+ for ( const root of roots ) {
342
+ for ( const extension of SOURCE_FILE_EXTENSIONS ) {
343
+ const file = join ( root , `${ page } .${ extension } ` )
344
+ if ( existsSync ( file ) ) {
345
+ return file
346
+ }
345
347
}
346
348
}
347
349
console . log ( 'Could not find source file for page' , page )
Original file line number Diff line number Diff line change @@ -169,11 +169,14 @@ export const setupImageFunction = async ({
169
169
export const getApiRouteConfigs = async ( publish : string , baseDir : string ) : Promise < Array < ApiRouteConfig > > => {
170
170
const pages = await readJSON ( join ( publish , 'server' , 'pages-manifest.json' ) )
171
171
const apiRoutes = Object . keys ( pages ) . filter ( ( page ) => page . startsWith ( '/api/' ) )
172
+ // two possible places
173
+ // Ref: https://nextjs.org/docs/advanced-features/src-directory
172
174
const pagesDir = join ( baseDir , 'pages' )
175
+ const srcPagesDir = join ( baseDir , 'src' , 'pages' )
173
176
174
177
return await Promise . all (
175
178
apiRoutes . map ( async ( apiRoute ) => {
176
- const filePath = getSourceFileForPage ( apiRoute , pagesDir )
179
+ const filePath = getSourceFileForPage ( apiRoute , [ pagesDir , srcPagesDir ] )
177
180
return { route : apiRoute , config : await extractConfigFromFile ( filePath ) , compiled : pages [ apiRoute ] }
178
181
} ) ,
179
182
)
You can’t perform that action at this time.
0 commit comments