@faapi/next 0.0.0-canary.0 → 0.0.0-canary.02bea8c
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.
- package/LICENSE +21 -0
- package/README.md +72 -0
- package/package.json +19 -26
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 faapi contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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,31 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faapi/next",
|
|
3
|
-
"version": "0.0.0-canary.
|
|
3
|
+
"version": "0.0.0-canary.02bea8c",
|
|
4
4
|
"description": "Next.js integration for faapi — serve faapi APIs and Next.js pages from a single server",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./
|
|
7
|
-
"types": "./
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./
|
|
11
|
-
"import": "./
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"engines": {
|
|
18
|
-
"node": ">=
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "tsup",
|
|
22
|
-
"prepublishOnly": "pnpm build",
|
|
23
|
-
"test": "vitest run --passWithNoTests",
|
|
24
|
-
"typecheck": "tsc --noEmit"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"@faapi/faapi": "workspace:*"
|
|
18
|
+
"node": ">=24"
|
|
28
19
|
},
|
|
20
|
+
"dependencies": {},
|
|
29
21
|
"devDependencies": {
|
|
30
22
|
"@types/node": "^22.15.0",
|
|
31
23
|
"@types/react": "^19.2.17",
|
|
@@ -37,10 +29,13 @@
|
|
|
37
29
|
"tsup": "^8.4.0",
|
|
38
30
|
"typescript": "^5.7.0",
|
|
39
31
|
"vitest": "^3.1.0",
|
|
40
|
-
"ws": "^8.21.0"
|
|
32
|
+
"ws": "^8.21.0",
|
|
33
|
+
"zod": "^4.4.3",
|
|
34
|
+
"@faapi/faapi": "0.0.0-canary.02bea8c"
|
|
41
35
|
},
|
|
42
36
|
"peerDependencies": {
|
|
43
|
-
"next": ">=13.0.0"
|
|
37
|
+
"next": ">=13.0.0",
|
|
38
|
+
"@faapi/faapi": "0.0.0-canary.02bea8c"
|
|
44
39
|
},
|
|
45
40
|
"peerDependenciesMeta": {
|
|
46
41
|
"next": {
|
|
@@ -55,13 +50,11 @@
|
|
|
55
50
|
},
|
|
56
51
|
"publishConfig": {
|
|
57
52
|
"access": "public",
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}
|
|
53
|
+
"provenance": true
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup",
|
|
57
|
+
"test": "vitest run --passWithNoTests",
|
|
58
|
+
"typecheck": "tsc --noEmit"
|
|
66
59
|
}
|
|
67
|
-
}
|
|
60
|
+
}
|