forked from enricoros/big-AGI
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'enricoros:main' into main
- Loading branch information
Showing
6 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { default as fs, renameSync } from 'fs'; | ||
import { dirname as pathDirName, join as pathJoin } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
|
||
// build-time configuration | ||
const buildOnlyFrontend = !!process.env.EXPORT_FRONTEND; | ||
|
||
|
||
function getApiDirName() { | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = pathDirName(__filename); | ||
return pathJoin(__dirname, '../app/api'); | ||
} | ||
|
||
function findAllFiles(startDir) { | ||
return fs.readdirSync(startDir).flatMap((file) => { | ||
const fullPath = pathJoin(startDir, file); | ||
if (fs.statSync(fullPath).isDirectory()) | ||
return findAllFiles(fullPath); | ||
return fullPath; | ||
}, | ||
); | ||
} | ||
|
||
/** | ||
* Hide/show API routes depending on the build type | ||
* Due to an upstream bug, NextJS will not ignore the nodejs API routes and choose to abort instead. | ||
*/ | ||
function prebuildFrontendHotFixes(hideFiles) { | ||
const apiDirName = getApiDirName(); | ||
const apiRoutesPaths = findAllFiles(apiDirName) | ||
.filter((path) => path.endsWith('.ts') || path.endsWith('.ts.backup')); | ||
|
||
apiRoutesPaths.forEach((path) => { | ||
const isBackup = path.endsWith('.backup'); | ||
if (hideFiles) { | ||
// If building the frontend, rename (effectively hide) the file | ||
!isBackup && renameSync(path, `${path}.backup`); | ||
} else { | ||
// If it's a normal build and including API routes and a backup exists, restore it | ||
isBackup && renameSync(path, path.slice(0, -7)); | ||
} | ||
}); | ||
} | ||
|
||
prebuildFrontendHotFixes(buildOnlyFrontend); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
718a4b3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
hi-zarina – ./
hi-zarina-icras-projects.vercel.app
big-agi-tan.vercel.app
hi.zarina.io
hi-zarina-git-main-icras-projects.vercel.app