Skip to content

Commit

Permalink
Merge pull request #2 from nestjs/master
Browse files Browse the repository at this point in the history
d
  • Loading branch information
cibucristi authored Jan 28, 2024
2 parents 1bce5b0 + 9de1d70 commit faba156
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion content/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ The `CatsService` is **injected** through the class constructor. Notice the use

#### Dependency injection

Nest is built around the strong design pattern commonly known as **Dependency injection**. We recommend reading a great article about this concept in the official [Angular](https://angular.io/guide/dependency-injection) documentation.
Nest is built around the strong design pattern commonly known as **Dependency injection**. We recommend reading a great article about this concept in the official [Angular](https://angular.dev/guide/di) documentation.

In Nest, thanks to TypeScript capabilities, it's extremely easy to manage dependencies because they are resolved just by type. In the example below, Nest will resolve the `catsService` by creating and returning an instance of `CatsService` (or, in the normal case of a singleton, returning the existing instance if it has already been requested elsewhere). This dependency is resolved and passed to your controller's constructor (or assigned to the indicated property):

Expand Down
8 changes: 4 additions & 4 deletions content/devtools/ci-cd.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ See screenshot below:

The ability to go back in time lets you investigate and troubleshoot the issue by comparing the current graph with the previous one. Depending on how you set things up, every pull request (or even every commit) will have a corresponding snapshot in the registry, so you can easily go back in time and see what changed. Think of Devtools as a Git but with an understanding of how Nest constructs your application graph, and with the ability to **visualize** it.

#### Integrations: Github Actions
#### Integrations: GitHub Actions

First let's start from creating a new Github workflow in the `.github/workflows` directory in our project and call it, for example, `publish-graph.yml`. Inside this file, let's use the following definition:
First let's start from creating a new GitHub workflow in the `.github/workflows` directory in our project and call it, for example, `publish-graph.yml`. Inside this file, let's use the following definition:

```yaml
name: Devtools
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
TARGET_SHA: {{ '${{' }} github.event.pull_request.base.sha {{ '}}' }}
```
Ideally, `DEVTOOLS_API_KEY` environment variable should be retrieved from Github Secrets, read more [here](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) .
Ideally, `DEVTOOLS_API_KEY` environment variable should be retrieved from GitHub Secrets, read more [here](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) .

This workflow will run per each pull request that's targeting the `master` branch OR in case there's a direct commit to the `master` branch. Feel free to align this configuration to whatever your project needs. What's essential here is that we provide necessary environment varaiables for our `GraphPublisher` class (to run).

Expand All @@ -150,7 +150,7 @@ const publishOptions = {
};
```

For the best developer experience, make sure to integrate the **Github application** for your project by clicking on the "Integrate Github app" button (see screenshot below). Note - this isn't required.
For the best developer experience, make sure to integrate the **GitHub application** for your project by clicking on the "Integrate GitHub app" button (see screenshot below). Note - this isn't required.

<figure><img src="/assets/devtools/integrate-github-app.png" /></figure>

Expand Down
2 changes: 1 addition & 1 deletion content/devtools/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Upon successful upload, you should see the following graph & dialog window:

<figure><img src="/assets/devtools/partial-graph-modules-view.png" /></figure>

As you can see, the highlighted `TasksModule` is the one we should look into. Also, in the dialog window you can already see some instructions on how to use fix this issue.
As you can see, the highlighted `TasksModule` is the one we should look into. Also, in the dialog window you can already see some instructions on how to fix this issue.

If we switch to the "Classes" view instead, that's what we'll see:

Expand Down
2 changes: 1 addition & 1 deletion content/faq/request-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class CatsController {

`Guard1` will execute before `Guard2` and both will execute before `Guard3`.

> info **Hint** When speaking about globally bound vs controller or locally bound, the difference is where the guard (or other component is bound). If you are using `app.useGlobalGuard()` or providing the component via a module, it is globally bound. Otherwise, it is bound to a controller if the decorator precedes a controller class, or to a route if the decorator proceeds a route declaration.
> info **Hint** When speaking about globally bound vs controller or locally bound, the difference is where the guard (or other component is bound). If you are using `app.useGlobalGuard()` or providing the component via a module, it is globally bound. Otherwise, it is bound to a controller if the decorator precedes a controller class, or to a route if the decorator precedes a route declaration.
#### Interceptors

Expand Down
2 changes: 1 addition & 1 deletion content/faq/serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ functions:
> info **Hint** To learn more about the Serverless framework, visit the [official documentation](https://www.serverless.com/framework/docs/).
With this place, we can now navigate to the `main.ts` file and update our bootstrap code with the required boilerplate:
With this in place, we can now navigate to the `main.ts` file and update our bootstrap code with the required boilerplate:

```typescript
import { NestFactory } from '@nestjs/core';
Expand Down
2 changes: 1 addition & 1 deletion content/fundamentals/lazy-loading-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ By default, modules are eagerly loaded, which means that as soon as the applicat

Lazy loading can help decrease bootstrap time by loading only modules required by the specific serverless function invocation. In addition, you could also load other modules asynchronously once the serverless function is "warm" to speed-up the bootstrap time for subsequent calls even further (deferred modules registration).

> info **Hint** If you're familiar with the **Angular** framework, you might have seen the "lazy-loading modules" term before. Be aware that this technique is **functionally different** in Nest and so think about this as an entirely different feature that shares similar naming conventions.
> info **Hint** If you're familiar with the **[Angular](https://angular.dev/)** framework, you might have seen the "[lazy-loading modules](https://angular.dev/guide/ngmodules/lazy-loading#lazy-loading-basics)" term before. Be aware that this technique is **functionally different** in Nest and so think about this as an entirely different feature that shares similar naming conventions.
> warning **Warning** Do note that [lifecycle hooks methods](https://docs.nestjs.com/fundamentals/lifecycle-events) are not invoked in lazy loaded modules and services.
Expand Down
2 changes: 1 addition & 1 deletion content/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ However, module classes themselves cannot be injected as providers due to [circu

#### Global modules

If you have to import the same set of modules everywhere, it can get tedious. Unlike in Nest, [Angular](https://angular.io) `providers` are registered in the global scope. Once defined, they're available everywhere. Nest, however, encapsulates providers inside the module scope. You aren't able to use a module's providers elsewhere without first importing the encapsulating module.
If you have to import the same set of modules everywhere, it can get tedious. Unlike in Nest, [Angular](https://angular.dev) `providers` are registered in the global scope. Once defined, they're available everywhere. Nest, however, encapsulates providers inside the module scope. You aren't able to use a module's providers elsewhere without first importing the encapsulating module.

When you want to provide a set of providers which should be available everywhere out-of-the-box (e.g., helpers, database connections, etc.), make the module **global** with the `@Global()` decorator.

Expand Down
5 changes: 4 additions & 1 deletion content/security/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ export class AuthService {
private jwtService: JwtService
) {}

async signIn(username, pass) {
async signIn(
username: string,
pass: string,
): Promise<{ access_token: string }> {
const user = await this.usersService.findOne(username);
if (user?.password !== pass) {
throw new UnauthorizedException();
Expand Down
17 changes: 6 additions & 11 deletions content/techniques/cookies.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can pass several options to the `cookieParser` middleware:

The middleware will parse the `Cookie` header on the request and expose the cookie data as the property `req.cookies` and, if a secret was provided, as the property `req.signedCookies`. These properties are name value pairs of the cookie name to cookie value.

When secret is provided, this module will unsign and validate any signed cookie values and move those name value pairs from `req.cookies` into `req.signedCookies`. A signed cookie is a cookie that has a value prefixed with `s:`. Signed cookies that fail signature validation will have the value `false` instead of the tampered value.
When a secret is provided, this module will unsign and validate any signed cookie values and move those name value pairs from `req.cookies` into `req.signedCookies`. A signed cookie is a cookie that has a value prefixed with `s:`. Signed cookies that fail signature validation will have the value `false` instead of the tampered value.

With this in place, you can now read cookies from within the route handlers, as follows:

Expand Down Expand Up @@ -67,10 +67,7 @@ Once the installation is complete, register the `@fastify/cookie` plugin:
import fastifyCookie from '@fastify/cookie';

// somewhere in your initialization file
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());
await app.register(fastifyCookie, {
secret: 'my-secret', // for cookies signature
});
Expand Down Expand Up @@ -109,12 +106,10 @@ To provide a convenient, declarative way of accessing incoming cookies, we can c
```typescript
import { createParamDecorator, ExecutionContext } from '@nestjs/common';

export const Cookies = createParamDecorator(
(data: string, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
return data ? request.cookies?.[data] : request.cookies;
},
);
export const Cookies = createParamDecorator((data: string, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
return data ? request.cookies?.[data] : request.cookies;
});
```

The `@Cookies()` decorator will extract all cookies, or a named cookie from the `req.cookies` object and populate the decorated parameter with that value.
Expand Down

0 comments on commit faba156

Please sign in to comment.