@@ -11,6 +11,7 @@ i18nReady: true
11
11
import PackageManagerTabs from ' ~/components/tabs/PackageManagerTabs.astro' ;
12
12
import Since from ' ~/components/Since.astro' ;
13
13
import ReadMore from ' ~/components/ReadMore.astro'
14
+ import { Steps } from ' @astrojs/starlight/components' ;
14
15
15
16
此适配器允许 Astro 将你的[ 按需渲染的路由] ( /zh-cn/guides/on-demand-rendering/ ) 部署到[ Vercel] ( https://www.vercel.com/ ) 。
16
17
@@ -401,8 +402,66 @@ declare namespace App {
401
402
```
402
403
403
404
### Node.js 版本支持
405
+
404
406
` @astrojs/vercel ` 适配器支持特定的 Node.js 版本,用于在 Vercel 上部署 Astro 项目。要在 Vercel 上查看受支持的 Node.js 版本,请单击项目的设置选项卡,然后向下滚动到 “Node.js版本” 部分。
405
407
406
- 查看[ Vercel文档] ( https://vercel.com/docs/functions/serverless-functions/runtimes/node-js#default-and-available-versions ) 了解更多信息。
408
+ 查看 [ Vercel 文档] ( https://vercel.com/docs/functions/serverless-functions/runtimes/node-js#default-and-available-versions ) 了解更多信息。
409
+
410
+ ### Sessions
411
+
412
+ Astro [ Session API] ( /zh-cn/guides/sessions/ ) 允许你在请求间,轻松地存储用户数据。该功能可用于用户数据和偏好选项,购物车内容,资格鉴权。不同于 cookie 存储,这里不存在对数据大小的限制,并且可以将其存储在不同的设备上。
413
+
414
+ 当你在 Vercel 上使用会话时,你需要为会话(session)存储 [ 配置驱动] ( /zh-cn/reference/configuration-reference/#sessiondriver ) 。你可以从 [ Vercel 插件市场] ( https://vercel.com/marketplace?category=storage ) 中安装一个存储集成。
415
+
416
+ 例如,如果你已经安装了 [ Redis 集成] ( https://vercel.com/marketplace?category=storage&search=redis ) 并将你的网站连接到了数据库:
417
+
418
+ <Steps >
419
+
420
+ 1 . 安装 ` ioredis ` 包:
421
+
422
+ <PackageManagerTabs >
423
+ <Fragment slot = " npm" >
424
+ ``` sh
425
+ npm install ioredis
426
+ ```
427
+ </Fragment >
428
+ <Fragment slot = " pnpm" >
429
+ ``` sh
430
+ pnpm install ioredis
431
+ ```
432
+ </Fragment >
433
+ <Fragment slot = " yarn" >
434
+ ``` sh
435
+ yarn add ioredis
436
+ ```
437
+ </Fragment >
438
+ </PackageManagerTabs >
439
+
440
+ 2 . 使用 [ Vercel CLI] ( https://vercel.com/docs/cli ) 来加载你的环境变量:
441
+
442
+ ``` sh
443
+ vercel env pull .env.local
444
+ ```
445
+
446
+ 这一步将会在你的项目根目录下创建一个 ` .env.local ` 文件,并会在进行本地开发时,提供连接到 Redis 数据库所需的环境变量。
447
+
448
+ 3 . 配置会话驱动:
449
+
450
+ ``` js title="astro.config.mjs" ins={6-11}
451
+ import { defineConfig } from ' astro/config' ;
452
+ import vercel from ' @astrojs/vercel' ;
453
+
454
+ export default defineConfig ({
455
+ adapter: vercel (),
456
+ session: {
457
+ driver: ' redis' ,
458
+ options: {
459
+ url: process .env .REDIS_URL ,
460
+ },
461
+ },
462
+ });
463
+ ```
464
+
465
+ </Steps >
407
466
408
467
[ astro-integration ] : /zh-cn/guides/integrations-guide/
0 commit comments