Skip to content

Commit e043cd1

Browse files
committed
fix:vercel1
1 parent 737010e commit e043cd1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Diff for: controllers/config.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ export default (fastify, options, done) => {
5050
let requestHost = cfg_path === '/1' ? `${protocol}://${hostname}` : `http://127.0.0.1:${options.PORT}`; // 动态生成根地址
5151
const siteJSON = generateSiteJSON(options.jsDir, requestHost);
5252
const siteStr = JSON.stringify(siteJSON, null, 2);
53-
writeFileSync(options.indexFilePath, siteStr, 'utf8'); // 写入 index.json
54-
if (cfg_path === '/1') {
55-
writeFileSync(options.customFilePath, siteStr, 'utf8'); // 写入 index.json
53+
if (!process.env.VERCEL) { // Vercel 环境不支持写文件,关闭此功能
54+
writeFileSync(options.indexFilePath, siteStr, 'utf8'); // 写入 index.json
55+
if (cfg_path === '/1') {
56+
writeFileSync(options.customFilePath, siteStr, 'utf8'); // 写入 index.json
57+
}
5658
}
5759
reply.send(siteJSON);
5860
} catch (error) {

Diff for: index.js

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ const start = async () => {
5555
console.log(`- Local: ${localAddress}`);
5656
console.log(`- LAN: ${lanAddress}`);
5757
console.log(`- PLATFORM: ${process.platform}`);
58+
if (process.env.VERCEL) {
59+
console.log('Running on Vercel!');
60+
console.log('Vercel Environment:', process.env.VERCEL_ENV); // development, preview, production
61+
console.log('Vercel URL:', process.env.VERCEL_URL);
62+
console.log('Vercel Region:', process.env.VERCEL_REGION);
63+
} else {
64+
console.log('Not running on Vercel!');
65+
}
66+
5867
} catch (err) {
5968
fastify.log.error(err);
6069
process.exit(1);

0 commit comments

Comments
 (0)