Revert "refactor: 优化serverless入口文件"

This reverts commit 1db354464fa20bed8dc70323c066fe12a2a02348.
This commit is contained in:
ElyPrism 2026-06-18 22:50:51 +08:00
parent 1db354464f
commit 2c9da8507d
No known key found for this signature in database
3 changed files with 6 additions and 33 deletions

8
app.js
View File

@ -8,9 +8,11 @@ async function start() {
if (!fs.existsSync(path.resolve(tmpPath, 'anonymous_token'))) {
fs.writeFileSync(path.resolve(tmpPath, 'anonymous_token'), '', 'utf-8')
}
// 启动时更新anonymous_token
const generateConfig = require('./generateConfig')
await generateConfig()
// 启动时更新anonymous_tokenVercel 构建环境下跳过网络请求喵~
if (!process.env.VERCEL_ENV) {
const generateConfig = require('./generateConfig')
await generateConfig()
}
require('./server').serveNcmApi({
checkVersion: true,
})

View File

@ -1,29 +1 @@
// Serverless 入口 + 本地开发通用入口
const fs = require('fs')
const path = require('path')
const tmpPath = require('os').tmpdir()
// 确保 anonymous_token 文件存在util/request.js 加载时需要读取)
if (!fs.existsSync(path.resolve(tmpPath, 'anonymous_token'))) {
fs.writeFileSync(path.resolve(tmpPath, 'anonymous_token'), '', 'utf-8')
}
const { constructServer } = require('./server')
const generateConfig = require('./generateConfig')
// Serverless 懒加载
let app = null
module.exports = async (req, res) => {
if (!app) {
await generateConfig()
app = await constructServer()
}
return app(req, res)
}
// Vercel判定
if (!process.env.VERCEL) {
require('./app.js')
}
require('./app.js')

View File

@ -456,6 +456,5 @@ async function serveNcmApi(options) {
module.exports = {
serveNcmApi,
constructServer,
getModulesDefinitions,
}