@faapi/next 0.0.0-canary.4ab8d97 → 0.0.0-canary.4e89b9b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +72 -0
  2. package/package.json +7 -6
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @faapi/next
2
+
3
+ > Next.js + faapi 单进程单端口集成
4
+
5
+ `@faapi/next` 让 faapi 和 Next.js 运行在同一个进程中,共享同一个端口。`/api/*` 路径走 faapi,其余路径走 Next.js,无需写 custom server 代码。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add @faapi/next next
11
+ # 或
12
+ npm install @faapi/next next
13
+ ```
14
+
15
+ 要求 Node.js >= 24,Next.js >= 13。
16
+
17
+ ## 快速开始
18
+
19
+ 在 `faapi.config.ts` 中声明插件:
20
+
21
+ ```ts
22
+ export default {
23
+ plugins: ['@faapi/next'],
24
+ } satisfies FaapiConfig;
25
+ ```
26
+
27
+ 然后像普通 faapi 项目一样启动:
28
+
29
+ ```bash
30
+ npx faapi
31
+ ```
32
+
33
+ `/api/*` 的请求由 faapi handler 处理,其余请求(页面、静态资源、HMR)由 Next.js 处理。
34
+
35
+ ### 自定义 API 前缀
36
+
37
+ ```ts
38
+ export default {
39
+ plugins: [
40
+ ['@faapi/next', { apiPrefix: '/v1' }],
41
+ ],
42
+ } satisfies FaapiConfig;
43
+ ```
44
+
45
+ ### 生产模式
46
+
47
+ ```bash
48
+ npx faapi build
49
+ node dist/main
50
+ ```
51
+
52
+ ## HTTP 分流
53
+
54
+ | 请求路径 | 处理方 |
55
+ |----------|--------|
56
+ | `/api/user` | faapi handler |
57
+ | `/api/hello?name=world` | faapi handler |
58
+ | `/` | Next.js 首页 |
59
+ | `/about` | Next.js 页面 |
60
+ | `/api2`(不匹配 /api 前缀) | Next.js |
61
+ | `/_next/*`(HMR / 静态资源) | Next.js |
62
+
63
+ ## WebSocket 分流
64
+
65
+ | upgrade 请求 | 处理方 |
66
+ |-------------|--------|
67
+ | `/api/chat`(faapi WS 路由) | faapi WebSocket handler |
68
+ | `/_next/webpack-hmr` | Next.js HMR |
69
+
70
+ ## 许可证
71
+
72
+ [MIT](https://github.com/faapi/faapi/blob/main/LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faapi/next",
3
- "version": "0.0.0-canary.4ab8d97",
3
+ "version": "0.0.0-canary.4e89b9b",
4
4
  "description": "Next.js integration for faapi — serve faapi APIs and Next.js pages from a single server",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,9 +17,7 @@
17
17
  "engines": {
18
18
  "node": ">=24"
19
19
  },
20
- "dependencies": {
21
- "@faapi/faapi": "0.0.0-canary.4ab8d97"
22
- },
20
+ "dependencies": {},
23
21
  "devDependencies": {
24
22
  "@types/node": "^22.15.0",
25
23
  "@types/react": "^19.2.17",
@@ -31,10 +29,13 @@
31
29
  "tsup": "^8.4.0",
32
30
  "typescript": "^5.7.0",
33
31
  "vitest": "^3.1.0",
34
- "ws": "^8.21.0"
32
+ "ws": "^8.21.0",
33
+ "zod": "^4.4.3",
34
+ "@faapi/faapi": "0.0.0-canary.4e89b9b"
35
35
  },
36
36
  "peerDependencies": {
37
- "next": ">=13.0.0"
37
+ "next": ">=13.0.0",
38
+ "@faapi/faapi": "0.0.0-canary.4e89b9b"
38
39
  },
39
40
  "peerDependenciesMeta": {
40
41
  "next": {