Skip to content

Commit

Permalink
feat(api-routes-vercel): Check there is vercel.json if user want to u…
Browse files Browse the repository at this point in the history
…se API routes in vercel (umijs#452)
  • Loading branch information
Yuanlin Lin authored Mar 9, 2022
1 parent 2253783 commit c3f771f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/preset-umi/src/features/apiRoute/apiRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ export default (api: IApi) => {
return false;
}

// 如果是 Vercel 平台,则需要检查是否有配置了 Vercel 配置
if (!fs.existsSync(join(api.paths.cwd, 'vercel.json'))) {
logger.warn(
'You have enabled the API route feature, but there is no vercel.json file in your work directory! ' +
'Automatically creating a vercel.json file ...',
);
fs.writeFileSync(
join(api.paths.cwd, 'vercel.json'),
JSON.stringify(
{ build: { env: { ENABLE_FILE_SYSTEM_API: '1' } } },
null,
2,
),
);
}

return true;
},
});
Expand Down

0 comments on commit c3f771f

Please sign in to comment.