mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-06-27 21:25:08 +00:00
Revert "refactor: 优化serverless入口文件"
This reverts commit 1db354464fa20bed8dc70323c066fe12a2a02348.
This commit is contained in:
parent
1db354464f
commit
2c9da8507d
4
app.js
4
app.js
@ -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
|
||||
// 启动时更新anonymous_token(Vercel 构建环境下跳过网络请求喵~)
|
||||
if (!process.env.VERCEL_ENV) {
|
||||
const generateConfig = require('./generateConfig')
|
||||
await generateConfig()
|
||||
}
|
||||
require('./server').serveNcmApi({
|
||||
checkVersion: true,
|
||||
})
|
||||
|
||||
28
index.js
28
index.js
@ -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')
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user