Files
2025-11-13 05:05:53 +08:00

27 lines
782 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export default {
async fetch(request, env) {
// 设置环境变量
process.env.GITHUB_CLIENT_ID = env.GITHUB_CLIENT_ID
process.env.GITHUB_SECRET = env.GITHUB_SECRET
process.env.GITHUB_OWNER = env.GITHUB_OWNER
process.env.GITHUB_REPO = env.GITHUB_REPO
process.env.GITHUB_BRANCH = env.GITHUB_BRANCH
process.env.NEXTAUTH_URL = env.NEXTAUTH_URL
process.env.NEXTAUTH_SECRET = env.GITHUB_SECRET
if (request.url.includes('/api/auth')) {
return env.ASSETS.fetch(request)
}
// 处理其他路由
try {
return await env.ASSETS.fetch(request)
} catch (e) {
// 如果是 404重定向到首页
if (e.status === 404) {
return Response.redirect(new URL('/', request.url))
}
throw e
}
}
}