Skip to content

Commit cb51126

Browse files
Merge branch 'fbartkow-from-f-examples-of-examples'
2 parents f20cd76 + 4c9fa8c commit cb51126

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

content/deployment.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $ npm run build
2424

2525
This command typically runs the `nest build` command and other the hood, which is basically a wrapper around the TypeScript compiler with some additional features (assets copying, etc.). In case you have a custom build script, you can run it directly. Also, for NestJS CLI mono-repos, make sure to pass the name of the project to build as an argument (`npm run build my-app`).
2626

27-
Upon successful compilation, you should see a `dist` directory in your project root containing the compiled files, with the entry point being `main.js`. If you have any `.ts` files located in the root directory of your project (and your `tsconfig.json` configured to compile them), they will be copied to the `dist` directory as well, modyfing the directory structure a bit (instead of `dist/main.js`, you will have `dist/src/main.js` so keep that in mind when configuring your server).
27+
Upon successful compilation, you should see a `dist` directory in your project root containing the compiled files, with the entry point being `main.js`. If you have any `.ts` files located in the root directory of your project (and your `tsconfig.json` configured to compile them), they will be copied to the `dist` directory as well, modifying the directory structure a bit (instead of `dist/main.js`, you will have `dist/src/main.js` so keep that in mind when configuring your server).
2828

2929
#### Production environment
3030

@@ -117,7 +117,7 @@ This process is straightforward with containerization technologies like [Docker]
117117
There are a few more tips to keep in mind when deploying your NestJS application:
118118

119119
- **Security**: Ensure your application is secure and protected from common threats like SQL injection, XSS, etc. See the "Security" category for more details.
120-
- **Monitoring**: Use monitoring tools like [Prometheus](https://prometheus.io/) or [New Relic](https://newrelic.com/) to track your application's performance and health. If you're using a cloud provider/Mau, they mau offer built-in monitoring services (like [AWS CloudWatch](https://aws.amazon.com/cloudwatch/) etc.)
120+
- **Monitoring**: Use monitoring tools like [Prometheus](https://prometheus.io/) or [New Relic](https://newrelic.com/) to track your application's performance and health. If you're using a cloud provider/Mau, they may offer built-in monitoring services (like [AWS CloudWatch](https://aws.amazon.com/cloudwatch/) etc.)
121121
- **Do not hardcode environment variables**: Avoid hardcoding sensitive information like API keys, passwords, or tokens in your code. Use environment variables or a secrets manager to store and access these values securely.
122122
- **Backups**: Regularly back up your data to prevent data loss in case of an incident.
123123
- **Automate deployments**: Use CI/CD pipelines to automate your deployment process and ensure consistency across environments.

content/openapi/types-and-parameters.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,31 @@ CatBreed:
203203

204204
> info **Hint** Any **decorator** that takes `enum` as a property will also take `enumName`.
205205

206+
#### Property value examples
207+
208+
You can set a single example for a property by using the `example` key, like this:
209+
210+
```typescript
211+
@ApiProperty({
212+
example: 'persian',
213+
})
214+
breed: string;
215+
```
216+
217+
If you want to provide multiple examples, you can use the `examples` key by passing in an object structured like this:
218+
219+
```typescript
220+
@ApiProperty({
221+
examples: {
222+
Persian: { value: 'persian' },
223+
Tabby: { value: 'tabby' },
224+
Siamese: { value: 'siamese' },
225+
'Scottish Fold': { value: 'scottish_fold' },
226+
},
227+
})
228+
breed: string;
229+
```
230+
206231
#### Raw definitions
207232

208233
In some specific scenarios (e.g., deeply nested arrays, matrices), you may want to describe your type by hand.
@@ -251,9 +276,10 @@ export class CreateCatDto {}
251276
Alternatively, you can pass an options object with the `extraModels` property specified to the `SwaggerModule#createDocument()` method, as follows:
252277

253278
```typescript
254-
const documentFactory = () => SwaggerModule.createDocument(app, options, {
255-
extraModels: [ExtraModel],
256-
});
279+
const documentFactory = () =>
280+
SwaggerModule.createDocument(app, options, {
281+
extraModels: [ExtraModel],
282+
});
257283
```
258284

259285
To get a reference (`$ref`) to your model, use the `getSchemaPath(ExtraModel)` function:

content/recipes/passport.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ The `validate()` method deserves some discussion. For the jwt-strategy, Passport
628628

629629
As a result of all this, our response to the `validate()` callback is trivial: we simply return an object containing the `userId` and `username` properties. Recall again that Passport will build a `user` object based on the return value of our `validate()` method, and attach it as a property on the `Request` object.
630630

631+
Additionally, you can return an array, where the first value is used to create a `user` object and the second value is used to create an `authInfo` object.
632+
631633
It's also worth pointing out that this approach leaves us room ('hooks' as it were) to inject other business logic into the process. For example, we could do a database lookup in our `validate()` method to extract more information about the user, resulting in a more enriched `user` object being available in our `Request`. This is also the place we may decide to do further token validation, such as looking up the `userId` in a list of revoked tokens, enabling us to perform token revocation. The model we've implemented here in our sample code is a fast, "stateless JWT" model, where each API call is immediately authorized based on the presence of a valid JWT, and a small bit of information about the requester (its `userId` and `username`) is available in our Request pipeline.
632634

633635
Add the new `JwtStrategy` as a provider in the `AuthModule`:

0 commit comments

Comments
 (0)