Open
Migrate backend APIs from Pages Router to App Router (pages unchanged)#95
Conversation
Copilot created this pull request from a session on behalf of
TechQuery
July 15, 2026 02:46
View session
There was a problem hiding this comment.
Pull request overview
This PR migrates server-side API endpoints from the Next.js Pages Router (pages/api) to App Router route handlers (app/api/**/route.ts) while keeping existing page routes and UI code paths intact. It also relocates shared non-route modules out of pages/api into lib/ to avoid Next.js treating them as API-route configuration.
Changes:
- Replaced Koa-based
pages/api/**endpoints with App Router route handlers for GitHub, Lark, signature verification, finance, and open-library APIs. - Extracted shared logic into
lib/(e.g.,lib/lark.ts,lib/ssg.ts) and updated imports in pages/models accordingly. - Temporarily disabled Husky hooks by making
pre-commit/pre-pushexit early.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pages/open-library/index.tsx | Switches book data import to models/open-library-books. |
| pages/open-library/books/index.tsx | Switches book data import to models/open-library-books. |
| pages/open-library/book/[id].tsx | Switches book data import to models/open-library-books. |
| pages/NGO/index.tsx | Updates Lark import to lib/lark. |
| pages/NGO/[year]/landscape.tsx | Updates Lark + SSG helper imports to lib/. |
| pages/NGO/[year]/index.tsx | Updates Lark + SSG helper imports to lib/. |
| pages/api/signature/[...slug].ts | Removes legacy Pages API route (replaced in app/api). |
| pages/api/Lark/mail/[address]/message.ts | Removes legacy Pages API route (replaced in app/api). |
| pages/api/Lark/file/[id]/[name].ts | Removes legacy Pages API route (replaced in app/api). |
| pages/api/Lark/document/markdown/[...slug].ts | Removes legacy Pages API route (replaced in app/api). |
| pages/api/Lark/document/copy/[...slug].ts | Removes legacy Pages API route (replaced in app/api). |
| pages/api/Lark/bitable/v1/[...slug].ts | Removes legacy Pages API route (replaced in app/api). |
| pages/api/Lark/bitable/schema/[...slug].tsx | Removes legacy Pages API route (replaced in app/api). |
| pages/api/GitHub/raw/[...slug].ts | Removes legacy Pages API route (replaced in app/api). |
| pages/api/GitHub/core.ts | Removes legacy proxy/OAuth helpers from Pages API. |
| pages/api/GitHub/[...slug].ts | Removes legacy Pages API route (replaced in app/api). |
| pages/api/core.ts | Removes legacy Koa/JWT safety middleware (replaced by lib/api/route-helper.ts). |
| models/Wiki.ts | Updates Lark import to lib/lark. |
| models/open-library-books.ts | Converts former API module into a pure data export. |
| lib/ssg.ts | Fixes configuration import path after moving out of pages/api. |
| lib/lark.ts | Moves Lark helpers out of pages/api into lib/. |
| lib/api/route-helper.ts | Adds shared helpers for JWT verification, body parsing, header forwarding, and error-to-Response mapping. |
| app/api/signature/verification/route.ts | New signature verification endpoint in App Router. |
| app/api/open-library/books/route.ts | New open-library books endpoint in App Router. |
| app/api/Lark/mail/bot/message/route.ts | New Lark mail bot endpoint in App Router. |
| app/api/Lark/file/[id]/[name]/route.ts | New Lark file download/proxy endpoint in App Router. |
| app/api/Lark/document/markdown/[type]/[id]/route.ts | New Lark markdown download endpoint in App Router. |
| app/api/Lark/document/copy/[type]/[id]/route.ts | New Lark document copy endpoint in App Router. |
| app/api/Lark/bitable/v1/[...slug]/route.ts | New Lark bitable proxy endpoint in App Router. |
| app/api/Lark/bitable/schema/[id]/route.ts | New Lark bitable schema endpoint in App Router. |
| app/api/GitHub/raw/[...slug]/route.ts | New GitHub raw proxy endpoint in App Router. |
| app/api/GitHub/[...slug]/route.ts | New GitHub API proxy endpoint in App Router. |
| app/api/finance/index-funds/route.ts | Migrates finance index-funds endpoint to App Router and updates query parsing. |
| .husky/pre-push | Temporarily bypasses pre-push checks (currently always exits 0). |
| .husky/pre-commit | Temporarily bypasses pre-commit checks (currently always exits 0). |
Comments suppressed due to low confidence (1)
lib/lark.ts:5
- lib/lark.ts imports koa as a runtime dependency even though Context/Middleware are only used as types. This can bloat server bundles (and can also unnecessarily couple route handlers to koa). Use a type-only import to avoid pulling koa into runtime code paths.
Comment on lines
+1
to
+2
| ## Temporarily bypassed to ensure blocked commits can still be submitted for review. | ||
| exit 0 |
Comment on lines
+1
to
+2
| ## Temporarily bypassed to ensure blocked pushes can still be submitted for review. | ||
| exit 0 |
Comment on lines
+14
to
+20
| export const verifyJWT = (request: NextRequest) => { | ||
| const token = request.cookies.get('token')?.value || cookieValueOf(request.headers.get('cookie') || '', 'token'); | ||
|
|
||
| if (!token) throw new Error('JWT token is required'); | ||
|
|
||
| return verify(token, LarkAppMeta.secret); | ||
| }; |
Comment on lines
+67
to
+76
| if (error instanceof HTTPError) { | ||
| const body = await normalizedBodyOf(error); | ||
|
|
||
| console.error(JSON.stringify(body, null, 2)); | ||
|
|
||
| return Response.json(body, { | ||
| status: error.response.status, | ||
| statusText: error.message, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本次变更将后端 API 从
pages/api迁移到app/api,并保持现有页面路由与页面实现不变;同时按要求临时关闭本地 Git hooks,避免提交/推送被钩子阻断。API 路由迁移(Pages API → App Route Handlers)
app/api/**/route.ts共享服务模块解耦
pages/api下但被页面/模型复用的非路由模块迁出至lib/pages/api/Lark/core.ts→lib/lark.tspages/api/SSG.ts→lib/ssg.tspages/NGO/**与models/Wiki.ts的 import,避免 Next 将其误判为 API route 配置文件旧 API 路由清理
pages/api路由文件,避免 Pages Router 与 App Router 并存导致重复/冲突实现按要求关闭本地 hooks
.husky/pre-commit、.husky/pre-push临时改为exit 0,确保代码可提交上来,再由后续讨论决定恢复策略示例(App Router Handler 形态):