Skip to content

Commit d480d4a

Browse files
committed
docs: 完善FAQ错误页面翻译并修复链接路径
1 parent 1af884d commit d480d4a

File tree

5 files changed

+82
-23
lines changed

5 files changed

+82
-23
lines changed

config/anchor-mappings.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,47 @@ const anchorMappings = {
332332
'basic-usage': '基本用法',
333333
'customization': '自定义',
334334

335+
// Security - Authentication (认证)
336+
'creating-an-authentication-module': '创建认证模块',
337+
'jwt-token': 'jwt-令牌',
338+
'implementing-the-authentication-endpoint': '实现认证端点',
339+
'implementing-the-authentication-guard': '实现认证守卫',
340+
'enable-authentication-globally': '启用全局认证',
341+
'passport-integration': 'passport-集成',
342+
'example': '示例',
343+
344+
// Security - Authorization (授权)
345+
'basic-rbac-implementation': '基本-rbac-实现',
346+
'claims-based-authorization': 'claims-based-authorization',
347+
'integrating-casl': '集成-casl',
348+
349+
// Security - CORS (跨域)
350+
'getting-started': '入门',
351+
352+
// Security - CSRF (跨站请求伪造)
353+
'use-with-express-default': '与-express-一起使用(默认)',
354+
'use-with-fastify': '与-fastify-一起使用',
355+
356+
// Security - Encryption & Hashing (加密和哈希)
357+
'encryption': '加密',
358+
'hashing': '哈希',
359+
360+
// Security - Helmet (头部安全)
361+
'use-with-express-default': '与-express-一起使用(默认)',
362+
'use-with-fastify': '与-fastify-一起使用',
363+
364+
// Security - Rate Limiting (速率限制)
365+
'multiple-throttler-definitions': '多重限流器定义',
366+
'customization': '自定义配置',
367+
'proxies': '代理',
368+
'websockets': 'websockets',
369+
'graphql': 'graphql',
370+
'configuration': '配置',
371+
'async-configuration': '异步配置',
372+
'storages': '存储',
373+
'time-helpers': '时间助手',
374+
'migration-guide': '迁移指南',
375+
335376
// CLI (命令行接口)
336377
'basic-workflow': '基本工作流程',
337378
'project-structure': '项目结构',
@@ -452,7 +493,16 @@ const pathMappings = {
452493
'/interceptors': '/overview/interceptors',
453494
'/exception-filters': '/overview/exception-filters',
454495
'/fundamentals/injection-scopes': '/fundamentals/provider-scopes',
455-
'/techniques/database': '/techniques/sql'
496+
'/techniques/database': '/techniques/sql',
497+
498+
// Security 路径映射
499+
'/security/authentication': '/security/authentication',
500+
'/security/authorization': '/security/authorization',
501+
'/security/cors': '/security/cors',
502+
'/security/csrf': '/security/csrf',
503+
'/security/encryption-hashing': '/security/encryption-hashing',
504+
'/security/helmet': '/security/helmet',
505+
'/security/rate-limiting': '/security/rate-limiting'
456506
};
457507

458508
// 导出配置(CommonJS)

docs/faq/errors.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44

55
#### "无法解析依赖项"错误
66

7-
> info **提示** 查看 [NestJS Devtools](/devtools/overview#调查无法解析依赖项错误) 可以帮助您轻松解决"无法解析依赖项"错误。
7+
> info **提示** 查看 [NestJS Devtools](./devtools/overview#调查无法解析依赖项错误) 可以帮助您轻松解决"无法解析依赖项"错误。
88
99
最常见的错误消息是关于 Nest 无法解析提供者的依赖项。错误消息通常如下所示:
1010

1111
```bash
12-
Nest can't resolve dependencies of the <provider> (?). Please make sure that the argument <unknown_token> at index [<index>] is available in the <module> context.
12+
Nest 无法解析 <provider> 的依赖项(?)。请确保索引 [<index>] 处的参数 <unknown_token><module> 上下文中可用。
1313

14-
Potential solutions:
15-
- Is <module> a valid NestJS module?
16-
- If <unknown_token> is a provider, is it part of the current <module>?
17-
- If <unknown_token> is exported from a separate @Module, is that module imported within <module>?
14+
可能的解决方案:
15+
- <module> 是否为有效的 NestJS 模块?
16+
- 如果 <unknown_token> 是提供者,它是否属于当前 <module>
17+
- 如果 <unknown_token> 从单独的 @Module 导出,该模块是否已在 <module> 中导入?
1818
@Module({
19-
imports: [ /* the Module containing <unknown_token> */ ]
19+
imports: [ /* 包含 <unknown_token> 的模块 */ ]
2020
})
2121
```
2222

23-
导致此错误最常见的原因是没有将 `<provider>` 放入模块的 `providers` 数组中。请确保该提供者确实位于 `providers` 数组中,并遵循[标准 NestJS 提供者实践](/fundamentals/custom-providers#di-基础)
23+
导致此错误最常见的原因是没有将 `<provider>` 放入模块的 `providers` 数组中。请确保该提供者确实位于 `providers` 数组中,并遵循[标准 NestJS 提供者实践](./fundamentals/custom-providers#di-基础)
2424

2525
有几个常见的陷阱需要注意。其中之一是将提供者放入了 `imports` 数组中。如果是这种情况,错误消息中会在 `<module>` 应该出现的位置显示提供者的名称。
2626

2727
在开发过程中遇到此错误时,请查看错误信息中提到的模块及其 `providers` 配置。对于 `providers` 数组中的每个提供者,请确保该模块能访问所有依赖项。常见情况是 `providers` 在"功能模块"和"根模块"中被重复声明,导致 Nest 会尝试实例化两次提供者。大多数情况下,包含重复 `<provider>` 的模块应该被添加到"根模块"的 `imports` 数组中。
2828

29-
如果上文的 `<unknown_token>` 是 `dependency`,可能存在循环文件导入。这与下文[循环依赖](/faq/common-errors#循环依赖错误)不同——不是指提供者在其构造函数中相互依赖,而是两个文件最终相互导入。典型场景是:模块文件声明令牌时导入提供者,而提供者又从模块文件导入令牌常量。如果使用桶文件,请确保桶文件导入不会形成此类循环导入关系。
29+
如果上文的 `<unknown_token>``dependency`,可能存在循环文件导入。这与下文[循环依赖](#循环依赖错误)不同——不是指提供者在其构造函数中相互依赖,而是两个文件最终相互导入。典型场景是:模块文件声明令牌时导入提供者,而提供者又从模块文件导入令牌常量。如果使用桶文件,请确保桶文件导入不会形成此类循环导入关系。
3030

3131
如果上方的 `<unknown_token>` 显示为 `Object`,说明您正在使用没有提供者令牌的类型/接口进行注入。要解决此问题,请确保:
3232

33-
1. 您已导入类引用或使用带有 `@Inject()` 装饰器的自定义令牌。请阅读[自定义提供者页面](/fundamentals/custom-providers) ,以及
33+
1. 您已导入类引用或使用带有 `@Inject()` 装饰器的自定义令牌。请阅读[自定义提供者页面](./fundamentals/custom-providers),以及
3434
2. 对于基于类的提供者,您导入的是具体类而不仅仅是 [`import type ...`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) 语法引入的类型。
3535

3636
同时请确保没有出现提供者自我注入的情况,因为 NestJS 不允许自我注入。当发生这种情况时,`<unknown_token>` 很可能会等于 `<provider>`
@@ -66,18 +66,18 @@ Nest 无法解析 <provider> 的依赖项(?)。
6666

6767
#### "循环依赖"错误
6868

69-
有时您会发现应用中难以避免[循环依赖](../fundamentals/circular-dependency)问题。您需要采取一些措施帮助 Nest 解决这些问题。由循环依赖引发的错误通常如下所示:
69+
有时您会发现应用中难以避免[循环依赖](./fundamentals/circular-dependency)问题。您需要采取一些措施帮助 Nest 解决这些问题。由循环依赖引发的错误通常如下所示:
7070

7171
```bash
72-
Nest cannot create the <module> instance.
73-
The module at index [<index>] of the <module> "imports" array is undefined.
72+
Nest 无法创建 <module> 实例。
73+
<module> "imports" 数组中索引 [<index>] 处的模块未定义。
7474

75-
Potential causes:
76-
- A circular dependency between modules. Use forwardRef() to avoid it. Read more: https://docs.nestjs.com/fundamentals/circular-dependency
77-
- The module at index [<index>] is of type "undefined". Check your import statements and the type of the module.
75+
可能的原因:
76+
- 模块间存在循环依赖。使用 forwardRef() 避免此问题。了解更多:./fundamentals/circular-dependency
77+
- 索引 [<index>] 处的模块类型为 "undefined"。检查您的导入语句和模块类型。
7878

79-
Scope [<module_import_chain>]
80-
# example chain AppModule -> FooModule
79+
作用域 [<module_import_chain>]
80+
# 示例链:AppModule -> FooModule
8181
```
8282

8383
循环依赖可能源于提供者之间相互依赖,或是 TypeScript 文件间因常量而相互依赖(例如从模块文件导出常量并在服务文件中导入)。对于后者,建议为常量创建单独的文件。对于前者,请遵循循环依赖指南,确保模块****提供者都使用 `forwardRef` 进行标记。
@@ -95,8 +95,8 @@ Scope [<module_import_chain>]
9595
使用 TypeScript 4.9 及以上版本的 Windows 用户可能会遇到此问题。当您尝试以监视模式运行应用程序时(例如 `npm run start:dev`),会出现日志消息的无限循环:
9696

9797
```bash
98-
XX:XX:XX AM - File change detected. Starting incremental compilation...
99-
XX:XX:XX AM - Found 0 errors. Watching for file changes.
98+
XX:XX:XX AM - 检测到文件变更。开始增量编译...
99+
XX:XX:XX AM - 发现 0 个错误。正在监视文件变更。
100100
```
101101

102102
当您使用 NestJS CLI 以监视模式启动应用程序时,实际上是通过调用 `tsc --watch` 实现的。从 TypeScript 4.9 版本开始,采用了一种 [新的策略](https://devblogs.microsoft.com/typescript/announcing-typescript-4-9/#file-watching-now-uses-file-system-events) 来检测文件变更,这很可能是导致此问题的原因。要解决此问题,您需要在 tsconfig.json 文件的 `"compilerOptions"` 选项后添加如下设置:

docs/openapi/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export interface SwaggerCustomOptions {
167167
/**
168168
* If `true`, Swagger resources paths will be prefixed by the global prefix set through `setGlobalPrefix()`.
169169
* Default: `false`.
170-
* @see https://docs.nestjs.com/faq/global-prefix
170+
* @see ../faq/global-prefix
171171
*/
172172
useGlobalPrefix?: boolean;
173173

docs/security/helmet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import helmet from 'helmet';
2020
app.use(helmet());
2121
```
2222

23-
> **警告** 当使用 `helmet``@apollo/server`(4.x)和 [Apollo Sandbox](https://docs.nestjs.com/graphql/quick-start#apollo-sandbox) 时,Apollo Sandbox 上可能会出现 [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) 问题。要解决此问题,请按如下所示配置 CSP:
23+
> **警告** 当使用 `helmet``@apollo/server`(4.x)和 [Apollo Sandbox](../graphql/quick-start#apollo-sandbox) 时,Apollo Sandbox 上可能会出现 [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) 问题。要解决此问题,请按如下所示配置 CSP:
2424
>
2525
> ```typescript
2626
> app.use(helmet({

scripts/replace-links.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ function urlPathToLocalPath(urlPath, currentFileDir) {
113113
'recipes/cors': '../recipes/cors',
114114
'recipes/mvc': '../recipes/mvc',
115115

116+
// Security 相关
117+
'security/authentication': '../security/authentication',
118+
'security/authorization': '../security/authorization',
119+
'security/cors': '../security/cors',
120+
'security/csrf': '../security/csrf',
121+
'security/encryption-hashing': '../security/encryption-hashing',
122+
'security/helmet': '../security/helmet',
123+
'security/rate-limiting': '../security/rate-limiting',
124+
116125
// GraphQL 相关
117126
'graphql/quick-start': '../graphql/quick-start',
118127
'graphql/resolvers-map': '../graphql/resolvers-map',

0 commit comments

Comments
 (0)