0%

vercel

1. Vercel

Vercel即支持Next.js也支持express,但是注意它们都是无状态的serverless。不支持长连接,如websocket。

接下来介绍下moonorepo的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"version": 2,
"builds": [
{
"src": "backend/api/index.ts",
"use": "@vercel/node"
},
{
"src": "frontend/next.config.js",
"use": "@vercel/next"
}
],
"rewrites": [
{
"source": "/api/(.*)",
"destination": "backend/api/index.ts"
},
{
"source": "/(.*)",
"destination": "frontend/$1"
}
]
}

这里注意使用了rewrites,不用使用routes,因为routes不支持动态链接,这个是好坑的,我在上面浪费了不少时间。混合渲染注意事项,后端渲染拿不到windows和localstoreage,所以这里要注意使用前端渲染去获取。更好的比方是,后端渲染返回了html,前端渲染使用JS。