Skip to content

Commit

Permalink
refactor: migrate to latest releases
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 24, 2023
1 parent 9470fd9 commit cab0a5b
Show file tree
Hide file tree
Showing 22 changed files with 1,904 additions and 2,396 deletions.
15 changes: 0 additions & 15 deletions .adonisrc.json

This file was deleted.

22 changes: 22 additions & 0 deletions adonisrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from '@adonisjs/core/app'

export default defineConfig({
typescript: true,
directories: {
views: 'templates',
} as any,
providers: [
() => import('@adonisjs/core/providers/app_provider'),
() => import('@adonisjs/core/providers/http_provider'),
() => import('@adonisjs/core/providers/edge_provider'),
() => import('@adonisjs/vite/vite_provider'),
() => import('@adonisjs/ally/ally_provider'),
() => import('@adonisjs/static/static_provider'),
],
metaFiles: [
{
pattern: './public/**/*',
reloadServer: false,
},
],
})
3 changes: 3 additions & 0 deletions assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import mediumZoom from 'medium-zoom'
import docsearch from '@docsearch/js'
import { tabs } from 'edge-uikit/tabs'
import Persist from '@alpinejs/persist'
import collapse from '@alpinejs/collapse'

import {
initZoomComponent,
initBaseComponents,
Expand All @@ -14,6 +16,7 @@ import.meta.glob(['../content/**/*.png', '../content/**/*.jpeg', '../content/**/

Alpine.plugin(tabs)
Alpine.plugin(Persist)
Alpine.plugin(collapse)
Alpine.plugin(initBaseComponents)
Alpine.plugin(initSearchComponent(docsearch))
Alpine.plugin(initZoomComponent(mediumZoom))
Expand Down
5 changes: 2 additions & 3 deletions bin/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import 'reflect-metadata'
import { Ignitor } from '@adonisjs/core'
import { defineConfig } from '@adonisjs/vite'

/**
* URL to the application root. AdonisJS need it to resolve
Expand Down Expand Up @@ -66,9 +67,7 @@ const app = new Ignitor(APP_ROOT, { importer: IMPORTER })
},
},
},
views: {
cache: false,
},
vite: defineConfig({}),
})
})
})
Expand Down
5 changes: 2 additions & 3 deletions bin/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Ignitor } from '@adonisjs/core'
import { Env } from '@adonisjs/core/env'
import { defineConfig } from '@adonisjs/ally'
import app from '@adonisjs/core/services/app'
import { defineConfig as viteDefineConfig } from '@adonisjs/vite'
import { defineConfig as httpConfig } from '@adonisjs/core/http'

import { isSponsoring } from '../src/sponsorable.js'
Expand Down Expand Up @@ -213,9 +214,7 @@ new Ignitor(APP_ROOT, { importer: IMPORTER })
},
},
},
views: {
cache: false,
},
vite: viteDefineConfig({}),
ally: allyConfig,
})
})
Expand Down
45 changes: 26 additions & 19 deletions content/docs/database/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ Once the package is installed, you must configure it using the `node ace configu
node ace configure @adonisjs/redis
```

:::disclosure{title="See steps performed by the configure command"}

1. Registers the following service provider inside the `adonisrc.ts` file.

```ts
{
providers: [
// ...other providers
() => import('@adonisjs/redis/redis_provider')
]
}
```

2. Create `config/redis.ts` file. This file contains the connection configuration for your redis server.

3. Define following environment variables and their validation rules.

```dotenv
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=
```

:::


## Configuration

The configuration for the Redis package is stored inside the `config/redis.ts` file.
Expand Down Expand Up @@ -112,25 +138,6 @@ const redisConfig = defineConfig({
})
```

### Environment variables usage

The `config/redis.ts` file internally relies on the following environment variables.

```dotenv
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=
```

Also, we recommend you to [validate the environment variables](../guides/env.md#validating-environment-variables) inside the `start/env.ts` file.

```ts
{
REDIS_HOST: Env.schema.string({ format: 'host' }),
REDIS_PORT: Env.schema.number(),
}
```

## Usage

You can run redis commands using the `redis` service exported by the package. The redis service is a singleton object configured using the configuration you have defined inside the `config/redis.ts` file.
Expand Down
33 changes: 19 additions & 14 deletions content/docs/digging_deeper/social_auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ Once the package is installed, you must configure it using the `node ace configu
node ace configure @adonisjs/ally
```

:::disclosure{title="See steps performed by the configure command"}

1. Registers the following service provider inside the `adonisrc.ts` file.

```ts
{
providers: [
// ...other providers
() => import('@adonisjs/ally/ally_provider')
]
}
```

2. Creates the `config/ally.ts` file. This file contains the configuration settings for selected OAuth providers.

3. Defines the environment variables to store `CLIENT_ID` and `CLIENT_SECRET` for selected OAuth providers.

:::

## Configuration
The `@adonisjs/ally` package configuration is stored inside the `config/ally.ts` file. You can define config for multiple services within a single config file.

Expand All @@ -67,20 +86,6 @@ defineConfig({
})
```

### Validating environment variables
You must store the client id and secret as environment variables and validate them to avoid runtime errors due to missing or incorrect values.

The [environment variables are validated](../guides/env.md#validating-environment-variables) inside the `start/env.ts` file.

```ts
{
GITHUB_CLIENT_ID: Env.schema.string(),
GITHUB_CLIENT_SECRET: Env.schema.string(),
TWITTER_CLIENT_ID: Env.schema.string(),
TWITTER_CLIENT_SECRET: Env.schema.string(),
}
```

### Configuring the callback URL
OAuth providers require you to register a callback URL to handle the redirect response after the user authorizes the login request.

Expand Down
1 change: 0 additions & 1 deletion content/docs/guides/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ yarn create adonisjs@latest hello-world
pnpm create adonisjs@latest hello-world
```


:::

## Starter kits
Expand Down
20 changes: 20 additions & 0 deletions content/docs/http/assets_bundling.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ Once the package is installed, you must configure it using the `node ace configu
node ace configure @adonisjs/vite
```

:::disclosure{title="See steps performed by the configure command"}

1. Registers the following service provider inside the `adonisrc.ts` file.

```ts
{
providers: [
// ...other providers
() => import('@adonisjs/vite/vite_provider')
]
}
```

2. Create `vite.config.js` and `config/vite.ts` configuration files.

3. Create the frontend entrypoint file, ie. `resources/js/app.js`.

:::


## Configuration
The setup process creates two configuration files. The `vite.config.js` file is used to configure the Vite bundler, and `config/vite.ts` is used by AdonisJS on the backend.

Expand Down
57 changes: 29 additions & 28 deletions content/docs/http/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,42 @@ pnpm add @adonisjs/session@next

:::

Once the package is installed, you must configure it using the `node ace configure` command.
Once done, you must run the following command to configure the session package.

```sh
node ace configure @adonisjs/session
```

Finally, you must register the session middleware inside the [router middleware stack](./middleware.md#router-middleware-stack).
:::disclosure{title="See steps performed by the configure command"}

```ts
// title: start/kernel.ts
import router from '@adonisjs/core/services/router'
1. Registers the following service provider inside the `adonisrc.ts` file.

router.use([
() => import('@adonisjs/core/bodyparser_middleware'),
// highlight-start
() => import('@adonisjs/session/session_middleware'),
// highlight-end
])
```
```ts
{
providers: [
// ...other providers
() => import('@adonisjs/session/session_provider')
]
}
```

2. Creates the `config/session.ts` file.

3. Defines the following environment variables and their validations.

```dotenv
SESSION_DRIVER=cookie
```

4. Registers the following middleware inside the `start/kernel.ts` file.

```ts
router.use([
() => import('@adonisjs/session/session_middleware')
])
```

:::

## Configuration
The configuration for the session package is stored inside the `config/session.ts` file.
Expand Down Expand Up @@ -197,22 +214,6 @@ Make sure to first install and configure the [@adonisjs/redis](../database/redis

</dl>

---

### Validating environment variables
The session config file relies on the `SESSION_DRIVER` environment variable to pick a session driver. We recommend you validate this environment variable to avoid runtime errors due to missing or incorrect values.

The [environment variables are validated](../guides/env.md#validating-environment-variables) inside the `start/env.ts` file.

```ts
// title: start/env.ts
{
SESSION_DRIVER: Env.schema.enum(
['redis', 'memory', 'cookie', 'file'] as const
),
}
```

## Basic example
Once you have registered the session middleware, you can access the `session` property from the [HTTP Context](./http_context.md). The session property exposes the API for reading and writing data to the session store.

Expand Down
34 changes: 25 additions & 9 deletions content/docs/http/static_file_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,36 @@ pnpm add @adonisjs/static

:::

Once the package is installed, you must configure it using the `node ace configure` command.
Once done, you must run the following command to configure the `@adonisjs/static` package.

```sh
node ace configure @adonisjs/static
```

Finally, register the middleware in the `start/kernel.ts` file.
:::disclosure{title="See steps performed by the configure command"}

```ts
// title: start/kernel.ts
server.use([
() => import('@adonisjs/static/static_middleware')
])
```
1. Registers the following service provider inside the `adonisrc.ts` file.

```ts
{
providers: [
// ...other providers
() => import('@adonisjs/static/static_provider')
]
}
```

2. Create the `config/static.ts` file.

3. Registers the following middleware inside the `start/kernel.ts` file.

```ts
server.use([
() => import('@adonisjs/static/static_middleware')
])
```

:::

## Serving static files

Expand All @@ -49,7 +65,7 @@ Once the middleware is registered, you may create files inside the `public` dire
<!-- The files in the `public` directory are not compiled or built using an assets bundler. If you want to compile frontend assets, you must place them inside the `resources` directory and use the [assets bundler](./assets_bundler.md). -->

## Copy static files to production build
In order to copy static files to the production build folder, you must register the `public` directory under the [metaFiles array](../fundamentals/adonisrc_file.md#metafiles) inside the `adonisrc.ts` file.
To copy static files to the production build folder, you must register the `public` directory under the [metaFiles array](../fundamentals/adonisrc_file.md#metafiles) inside the `adonisrc.ts` file.

```ts
{
Expand Down
16 changes: 13 additions & 3 deletions content/docs/http/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ Once done, you must run the following command to configure VineJS within an Adon
node ace configure vinejs
```

The `configure` command will register the `@adonisjs/core/providers/vinejs_provider` provider within the `adonisrc.ts` file. The VineJS service provider will perform the following tasks.
:::disclosure{title="See steps performed by the configure command"}

- Add `validateUsing` method to the [Request](./request.md) class.
- Add file validation rule to VineJS.
1. Registers the following service provider inside the `adonisrc.ts` file.

```ts
{
providers: [
// ...other providers
() => import('@adonisjs/core/providers/vinejs_provider')
]
}
```

:::

## Using VineJS validators
VineJS uses the concept of validators. You create one validator for each action your application can perform. For example: Define a validator for **creating a new post**, another for **updating the post**, and maybe a validator for **deleting a post**.
Expand Down
Loading

0 comments on commit cab0a5b

Please sign in to comment.