Skip to content

Commit

Permalink
feat: add env validator doc (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Jul 17, 2023
1 parent 1e2f5e4 commit 3c87236
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/providers/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Providers",
"position": 3,
"link": {
"type": "generated-index",
"description": "ExpressoTS Framework Providers."
}
}
49 changes: 49 additions & 0 deletions docs/providers/envvalidator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
sidebar_position: 1
---

# Environment validator

The environment validator provider is a provider that ExpressoTS offers out-of-the-box. It is used to validate the existence of the `.env` file and its content.
It helps the developer to avoid runtime errors caused by missing environment variables.

:::tip
It is only included in the opinionated template or when you create a class that extends the `Application` class.
:::

You can find it in the `src/providers/application` folder in the opinionated template.

The `application.provider` is the main provider of the application that is responsible to control the **[Application Lifecycle](../overview/application.md#application-lifecycle-hooks)**.

Inside of the Application class you can find three methods that are called in the following order:

- `configureServices()` : Configure services that should be initialized before the server starts.
- `postServerInitialization()` : Configure services that should be executed after the server starts.
- `serverShutdown()` : Perform actions or cleanup after the server is shutdown.

Environment validator provider is called in the `configureServices()` method preventing the application to start if the `.env` file is missing or if it has missing environment variables.

```typescript
protected configureServices(): void {
Environments.checkAll();
}
```

The environment validator provider also has a method called `get()` that returns the value of an environment variable. It is used to get a specific environment variable value passing its name as a parameter.

```typescript
Environments.get("PORT");
```

---

## Support the project

ExpressoTS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:

- Become a sponsor on **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
- Follow the **[organization](https://github.com/expressots)** on GitHub and Star ⭐ the project
- Subscribe to the Twitch channel: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
- Join our **[Discord](https://discord.com/invite/PyPJfGK)**
- Contribute submitting **[issues and pull requests](https://github.com/expressots/expressots/issues/new/choose)**
- Share the project with your friends and colleagues
20 changes: 20 additions & 0 deletions docs/providers/prisma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
sidebar_position: 2
---

# Prisma provider

Coming soon...

---

## Support the project

ExpressoTS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:

- Become a sponsor on **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
- Follow the **[organization](https://github.com/expressots)** on GitHub and Star ⭐ the project
- Subscribe to the Twitch channel: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
- Join our **[Discord](https://discord.com/invite/PyPJfGK)**
- Contribute submitting **[issues and pull requests](https://github.com/expressots/expressots/issues/new/choose)**
- Share the project with your friends and colleagues
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const config = {
announcementBar: {
id: 'supportus',
content:
'Current Version: v1.5.0',
'Current Version: v1.5.1',
backgroundColor: '#111',
textColor: '#19CE59',
isCloseable: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Provedores",
"position": 3,
"link": {
"type": "generated-index",
"description": "ExpressoTS Framework Provedores."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
sidebar_position: 1
---

# Validator de ambiente

O provedor de validação de ambiente é um provedor que o ExpressoTS oferece por padrão. Ele é usado para validar a existência do arquivo `.env` e seu conteúdo.
Ele ajuda o desenvolvedor a evitar erros em tempo de execução causados por variáveis de ambiente ausentes.

:::tip
Ele está incluso apenas no modelo opinativo ou quando você cria uma classe que estende a classe `Application`.
:::

Você pode encontrá-lo na pasta `src/providers/application` no modelo opinativo.

O `application.provider` é o provedor principal do aplicativo responsável por controlar o **[Application Lifecycle](../overview/application.md#application-lifecycle-hooks)**.

Dentro da classe Application você pode encontrar três métodos que são chamados na seguinte ordem:

- `configureServices()` : Configura serviços que devem ser inicializados antes do início do servidor.
- `postServerInitialization()` : Configura serviços que devem ser executados após o início do servidor.
- `serverShutdown()` : Realiza ações ou limpezas após o desligamento do servidor.

O provedor de validação de ambiente é chamado no método `configureServices()`, prevenindo que o aplicativo inicie se o arquivo `.env` estiver faltando ou se tiver variáveis de ambiente ausentes.

```typescript
protected configureServices(): void {
Environments.checkAll();
}
```

O provedor de validação de ambiente também tem um método chamado `get()` que retorna o valor de uma variável de ambiente. Ele é usado para obter um valor específico de variável de ambiente passando seu nome como parâmetro.

```typescript
Environments.get("PORT");
```

---

## Apoie o projeto

ExpressoTS é um projeto de código aberto licenciado sob o MIT. É um projeto independente com desenvolvimento contínuo possibilitado graças ao seu suporte. Se você deseja ajudar, por favor considere:

- Se tornar um **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
- Siga a **[organização](https://github.com/expressots)** no GitHub e de um Star ⭐ no projeto
- Subscreva no nosso canal na Twitch: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
- Entre no nosso **[Discord](https://discord.com/invite/PyPJfGK)**
- Contribua submetendo **[issues e pull requests](https://github.com/expressots/expressots/issues/new/choose)**
- Compartilhe o projeto com seus amigos e colegas
20 changes: 20 additions & 0 deletions i18n/pt/docusaurus-plugin-content-docs/current/providers/prisma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
sidebar_position: 2
---

# Prisma provedor

Em breve...

---

## Apoie o projeto

ExpressoTS é um projeto de código aberto licenciado sob o MIT. É um projeto independente com desenvolvimento contínuo possibilitado graças ao seu suporte. Se você deseja ajudar, por favor considere:

- Se tornar um **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
- Siga a **[organização](https://github.com/expressots)** no GitHub e de um Star ⭐ no projeto
- Subscreva no nosso canal na Twitch: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
- Entre no nosso **[Discord](https://discord.com/invite/PyPJfGK)**
- Contribua submetendo **[issues e pull requests](https://github.com/expressots/expressots/issues/new/choose)**
- Compartilhe o projeto com seus amigos e colegas

0 comments on commit 3c87236

Please sign in to comment.