File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
packages/runtime/src/helpers Expand file tree Collapse file tree 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) => {
337337/**
338338 * Find the source file for a given page route
339339 */
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+ }
345347 }
346348 }
347349 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 ({
169169export const getApiRouteConfigs = async ( publish : string , baseDir : string ) : Promise < Array < ApiRouteConfig > > => {
170170 const pages = await readJSON ( join ( publish , 'server' , 'pages-manifest.json' ) )
171171 const apiRoutes = Object . keys ( pages ) . filter ( ( page ) => page . startsWith ( '/api/' ) )
172+ // two possible places
173+ // Ref: https://nextjs.org/docs/advanced-features/src-directory
172174 const pagesDir = join ( baseDir , 'pages' )
175+ const srcPagesDir = join ( baseDir , 'src' , 'pages' )
173176
174177 return await Promise . all (
175178 apiRoutes . map ( async ( apiRoute ) => {
176- const filePath = getSourceFileForPage ( apiRoute , pagesDir )
179+ const filePath = getSourceFileForPage ( apiRoute , [ pagesDir , srcPagesDir ] )
177180 return { route : apiRoute , config : await extractConfigFromFile ( filePath ) , compiled : pages [ apiRoute ] }
178181 } ) ,
179182 )
You can’t perform that action at this time.
0 commit comments