Skip to content

Commit

Permalink
Merge pull request #1242 from FoalTS/docusaurus-3
Browse files Browse the repository at this point in the history
[Docs] Prepare to upgrade to Docusaurus v3
  • Loading branch information
LoicPoullain authored Nov 5, 2023
2 parents 67b7b7e + a861e0f commit 00eba3f
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 831 deletions.
108 changes: 3 additions & 105 deletions docs/docs/architecture/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
title: Configuration
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';


In FoalTS, _configuration_ refers to any parameter that may vary between deploy environments (production, development, test, etc). It includes sensitive information, such as your database credentials, or simple settings, such as the server port.

The framework encourages a **strict separation between configuration and code** and allows you to define your configuration in environment variables, in `.env` files and in files in the `config/` directory.
Expand All @@ -27,27 +23,14 @@ The framework encourages a **strict separation between configuration and code**

Configuration values are provided using configuration files in the `config/` directory. Several formats are supported: YAML, JSON and JS files.

*config/default.{yml|json|js}*

<Tabs
defaultValue="yaml"
values={[
{label: 'YAML', value: 'yaml'},
{label: 'JSON', value: 'json'},
{label: 'JS', value: 'js'},
]}
>
<TabItem value="yaml">
*config/default.yml*
```yaml
settings:
session:
store: "@foal/typeorm"
```
</TabItem>
<TabItem value="json">
*config/default.json*
```json
{
"settings": {
Expand All @@ -58,9 +41,7 @@ settings:
}
```

</TabItem>
<TabItem value="js">

*config/default.js*
```javascript
module.exports = {
settings: {
Expand All @@ -71,9 +52,6 @@ module.exports = {
}
```

</TabItem>
</Tabs>

> **YAML support**
>
> The use of YAML for configuration requires the installation of the package `yamljs`.
Expand Down Expand Up @@ -102,28 +80,6 @@ Configuration values can also be set or overridden for a specific environment us
All parameters under the keyword `settings` are reserved for the operation of the framework. You can assign values to those given in the documentation, but you cannot create new ones.
<Tabs
defaultValue="yaml"
values={[
{label: 'YAML', value: 'yaml'},
{label: 'JSON', value: 'json'},
{label: 'JS', value: 'js'},
]}
>
<TabItem value="yaml">
```yaml
settings:
session:
store: "@foal/typeorm"
customConfiguration:
message: hello world
```
</TabItem>
<TabItem value="json">

```json
{
"settings": {
Expand All @@ -137,25 +93,6 @@ customConfiguration:
}
```
</TabItem>
<TabItem value="js">

```javascript
module.exports = {
settings: {
session: {
store: "@foal/typeorm"
}
},
customConfiguration: {
message: "hello world"
}
}
```

</TabItem>
</Tabs>

## Accessing Configuration Values

The `Config` class provides two static methods `get` and `getOrThrow` for reading configuration values.
Expand Down Expand Up @@ -226,26 +163,6 @@ The recommended approach to provide sensitive information to the application is
JWT_SECRET="Ak0WcVcGuOoFuZ4oqF1tgqbW6dIAeSacIN6h7qEyJM8="
```

<Tabs
defaultValue="yaml"
values={[
{label: 'YAML', value: 'yaml'},
{label: 'JSON', value: 'json'},
{label: 'JS', value: 'js'},
]}
>
<TabItem value="yaml">
```yaml
settings:
jwt:
secret: env(JWT_SECRET)
secretEncoding: base64
```
</TabItem>
<TabItem value="json">
```json
{
"settings": {
Expand All @@ -257,25 +174,6 @@ settings:
}
```

</TabItem>
<TabItem value="js">

```javascript
const { Env } = require('@foal/core');

module.exports = {
settings: {
jwt: {
secret: Env.get('JWT_SECRET'),
secretEncoding: 'base64'
}
}
}
```

</TabItem>
</Tabs>

If the same variable is provided both as environment variable and in the `.env` file, then the value of the environment variable is used.

### Deployment Environments
Expand Down
101 changes: 2 additions & 99 deletions docs/docs/databases/typeorm/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ title: TypeORM
sidebar_label: Introduction
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';


*A simple model:*
```typescript
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
Expand Down Expand Up @@ -78,33 +74,7 @@ Two packages are required to use TypeORM with FoalTS:
npm install pg
```

*config/default.{json|yml|js}*

<Tabs
defaultValue="yaml"
values={[
{label: 'YAML', value: 'yaml'},
{label: 'JSON', value: 'json'},
{label: 'JS', value: 'js'},
]}
>
<TabItem value="yaml">
```yaml
# ...

database:
type: postgres
host: localhost
port: 5432
username: root
password: password
database: my-db
```
</TabItem>
<TabItem value="json">
*config/default.json*
```json
{
// ...
Expand All @@ -120,59 +90,13 @@ database:
}
```

</TabItem>
<TabItem value="js">

```javascript
module.exports = {
// ...

database: {
type: "postgres",
host: "localhost",
port: 5432,
username: "root",
password: "password",
database: "my-db"
}
}
```

</TabItem>
</Tabs>

### MySQL

```sh
npm install mysql
```

*config/default.{json|yml|js}*

<Tabs
defaultValue="yaml"
values={[
{label: 'YAML', value: 'yaml'},
{label: 'JSON', value: 'json'},
{label: 'JS', value: 'js'},
]}
>
<TabItem value="yaml">
```yaml
# ...

database:
type: mysql
host: localhost
port: 3306
username: root
password: password
database: my-db
```
</TabItem>
<TabItem value="json">
*config/default.json*

```json
{
Expand All @@ -189,27 +113,6 @@ database:
}
```

</TabItem>
<TabItem value="js">

```javascript
module.exports = {
// ...

database: {
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "password",
database: "my-db"
}
}
```

</TabItem>
</Tabs>

## Configuration and Testing

When running the command `npm run test` with the above configuration, FoalTS will try to retrieve the database configuration in this order:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,6 @@ By default, UTF-8 is used to encode the secret string into bytes when verifying

Available encodings are listed [here](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings).

{% code-tabs %}
{% code-tabs-item title="YAML" %}
```yaml
settings:
jwt:
secretOrPublicKey: HEwh0TW7w6a5yUwIrpHilUqetAqTFAVSHx2rg6DWNtg=
secretEncoding: base64
```
{% endcode-tabs-item %}
{% code-tabs-item title="JSON" %}
```json
{
"settings": {
Expand All @@ -375,14 +365,6 @@ settings:
}
}
```
{% endcode-tabs-item %}
{% code-tabs-item title=".env or environment variables" %}
```
SETTINGS_JWT_SECRET_OR_PUBLIC_KEY=HEwh0TW7w6a5yUwIrpHilUqetAqTFAVSHx2rg6DWNtg=
SETTINGS_JWT_SECRET_ENCODING=base64
```
{% endcode-tabs-item %}
{% endcode-tabs %}

## Store JWTs in a cookie

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ The `verifyPassword` takes three arguments:
Promise<boolean>
```

> If you used the `parsePassword` function in previous versions of Foal (<0.7.0), you must pass the `legacy: true` option to `verifyPassword` and `hashPassword`.
> If you used the `parsePassword` function in previous versions of Foal (< 0.7.0), you must pass the `legacy: true` option to `verifyPassword` and `hashPassword`.
11 changes: 3 additions & 8 deletions docs/versioned_docs/version-1.x/databases/typeorm.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ module.exports = {

With this configuration, database credentials can be provided in a YAML, a JSON or a `.env `configuration file or in environment variables.

{% code-tabs %}
{% code-tabs-item title="config/default.yml" %}
```yaml
# ...

Expand All @@ -132,8 +130,7 @@ database:
password: password
database: my-db
```
{% endcode-tabs-item %}
{% code-tabs-item title="config/default.json" %}
```json
{
// ...
Expand All @@ -146,17 +143,15 @@ database:
}
}
```
{% endcode-tabs-item %}
{% code-tabs-item title=".env or environment variables" %}

```json
DATABASE_HOST=localhost
DATABASE_PORT=3306
DATABASE_USERNAME=root
DATABASE_PASSWORD=password
DATABASE_DATABASE=my-db
```
{% endcode-tabs-item %}
{% endcode-tabs %}


### MySQL / MariaDB

Expand Down
Loading

0 comments on commit 00eba3f

Please sign in to comment.