From 1bb9376f69f4c80c60beb23d721e8d0a58e04272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 11:31:36 -0300 Subject: [PATCH 1/9] refactor(docs): change paths to use Path helper --- .../application-lifecycle.mdx | 19 +++++++++---------- .../service-container.mdx | 2 +- docs/cli-application/error-handling.mdx | 6 +++--- docs/digging-deeper/graceful-shutdown.mdx | 2 +- docs/getting-started/configuration.mdx | 4 ++-- docs/getting-started/directory-structure.mdx | 2 +- docs/rest-api-application/error-handling.mdx | 10 +++++----- docs/rest-api-application/middlewares.mdx | 2 +- docs/rest-api-application/rate-limiting.mdx | 4 ++-- docs/rest-api-application/routing.mdx | 4 ++-- docs/rest-api-application/swagger.mdx | 4 ++-- .../rest-api-application/tracing-requests.mdx | 2 +- docs/the-basics/logging.mdx | 18 +++++++++--------- docs/the-basics/views.mdx | 4 ++-- 14 files changed, 41 insertions(+), 42 deletions(-) diff --git a/docs/architecture-concepts/application-lifecycle.mdx b/docs/architecture-concepts/application-lifecycle.mdx index 3d8dd7f2..404c4b40 100644 --- a/docs/architecture-concepts/application-lifecycle.mdx +++ b/docs/architecture-concepts/application-lifecycle.mdx @@ -35,10 +35,9 @@ application you are using. Meaning that no matter what is the type of application you are using to build your solution, the explanation bellow is valid for all of them. -The entry point of an Athenna application is the `bootstrap/main.ts` -file in the default project structure and `bin/main.ts` in slim project -structure. The first action taken by Athenna itself is to create an -instance of the application and then boot it. +The entry point of an Athenna application is the `Path.bootstrap('main.ts')`. +The first action taken by Athenna itself is to create an instance of the +application and then boot it. ## Loading the foundation @@ -141,7 +140,7 @@ will be fired before executing your command. ### Kernel The Kernel class is responsible by defining some bootstraps that will -be run before reading your `routes/http.ts` file. These bootstraps +be run before reading your `Path.routes('http.ts')` file. These bootstraps configure error handling for requests, tracing and logging, detect the application environment, and perform other tasks that need to be done before the request is actually handled. Typically, these classes handle @@ -169,7 +168,7 @@ implementation code. ::: -Then, you can register your `CustomKernel` in your `bootstrap/main.ts` +Then, you can register your `CustomKernel` in your `Path.bootstrap('main.ts')` file: ```typescript @@ -177,19 +176,19 @@ import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url) -await ignite.httpServer({ kernelPath: '#app/http/CustomKernel' })' +await ignite.httpServer({ kernelPath: '#app/http/CustomKernel' }) ``` ### Routes -The `routes/http.ts` file is the entrypoint for all your http requests. +The `Path.routes('http.ts')` file is the entrypoint for all your http requests. This file is responsible to create a contract between your client and your application. It Is in here that we define all our routes and the handlers/controllers who will handle the client request. One of the most important service providers in your application is the `HttpRouteProvider`. This service provider adds in the container the -`Route` class instance used inside `routes/http.ts` file. +`Route` class instance used inside `Path.routes('http.ts')` file. When the client request arrives, the server first executes all your global middlewares, then it will execute all your route middlewares. @@ -291,7 +290,7 @@ await ignite.artisan({ kernelPath: '#app/http/CustomKernel' }) ### Execution -The `routes/console.ts` and the `commands` property of `.athennarc.json` file +The `Path.routes('console.ts')` and the `commands` property of `.athennarc.json` file is where that we define all ours commands and the handlers who will handle the terminal arguments. diff --git a/docs/architecture-concepts/service-container.mdx b/docs/architecture-concepts/service-container.mdx index e9331d82..d0923f53 100644 --- a/docs/architecture-concepts/service-container.mdx +++ b/docs/architecture-concepts/service-container.mdx @@ -56,7 +56,7 @@ itself. If you use the `@Service` annotation, you can instruct the container how he should resolve that class, or use the default resolution configurations of the annotation. For example, you may place the following code in your -`routes/http.ts` file: +`Path.routes('http.ts')` file: ```typescript import { Route } from '@athenna/http' diff --git a/docs/cli-application/error-handling.mdx b/docs/cli-application/error-handling.mdx index e84d7609..43325428 100644 --- a/docs/cli-application/error-handling.mdx +++ b/docs/cli-application/error-handling.mdx @@ -62,7 +62,7 @@ bootstrap failure has been found in your application. ## Configuration -The `debug` option in your `config/app.ts` configuration +The `debug` option in your `Path.config('app.ts')` configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the `APP_DEBUG` environment @@ -77,13 +77,13 @@ users. Every error will be logged by default using the `console` driver from `@athenna/logger`. By default, Athenna uses the -`exception` channel of your `config/logging.ts` file to log +`exception` channel of your `Path.config('logging.ts')` file to log all exceptions that happens in your application. :::tip You can change the driver and formatter of `exception` -channel inside `config/logging.ts` file. This way you can +channel inside `Path.config('logging.ts')` file. This way you can send all your error logs to another provider and with a different formatter. diff --git a/docs/digging-deeper/graceful-shutdown.mdx b/docs/digging-deeper/graceful-shutdown.mdx index f530cbd9..7b7184c2 100644 --- a/docs/digging-deeper/graceful-shutdown.mdx +++ b/docs/digging-deeper/graceful-shutdown.mdx @@ -125,7 +125,7 @@ process.on('SIGTERM', () => { If you wish to remove or change the default listeners of Athenna, or also listen to new signals, you can create -the `signals` property in the `config/app.ts` +the `signals` property in the `Path.config('app.ts')` file: ```typescript diff --git a/docs/getting-started/configuration.mdx b/docs/getting-started/configuration.mdx index b6a9ae00..73597a3b 100644 --- a/docs/getting-started/configuration.mdx +++ b/docs/getting-started/configuration.mdx @@ -338,7 +338,7 @@ Config.set('app.name', builders.functionCall('Env', ['MY_APP_NAME'])) await Config.rewrite('app') ``` -The example above will produce the following code in `config/app.ts`: +The example above will produce the following code in `Path.config('app.ts')`: ```typescript export default { @@ -525,7 +525,7 @@ structure. ## Debug mode -The `debug` option in your `config/app.ts` configuration +The `debug` option in your `Path.config('app.ts')` configuration file determines how much information about your application is actually displayed to you and for who is going to consume your application. By default, this option is set to respect diff --git a/docs/getting-started/directory-structure.mdx b/docs/getting-started/directory-structure.mdx index 8b4ee199..1b7b7f2e 100644 --- a/docs/getting-started/directory-structure.mdx +++ b/docs/getting-started/directory-structure.mdx @@ -153,7 +153,7 @@ command, Athenna will use this file to run your application. - The `config` path is where you are going to set up your configuration files. You can learn more about configuration files at [the configuration documentation section](https://athenna.io/docs/getting-started/configuration). -- The `routes/http.ts` file is where you are going to register +- The `Path.routes('http.ts')` file is where you are going to register your Http server routes. Athenna is a framework with a lot of opinions, with predefined diff --git a/docs/rest-api-application/error-handling.mdx b/docs/rest-api-application/error-handling.mdx index c38bf09c..65826265 100644 --- a/docs/rest-api-application/error-handling.mdx +++ b/docs/rest-api-application/error-handling.mdx @@ -22,7 +22,7 @@ This documentation will cover about error handling in the **REST API** application, which means that only errors that happens inside routes and bellow that will be handled: -```typescript title="routes/http.ts" +```typescript title="Path.routes('http.ts')" import { Route } from '@athenna/http' // If AppController.show throws, HttpExceptionHandler will handle it 👈 @@ -44,7 +44,7 @@ bootstrap failure has been found in your application. ## Configuration -The `debug` option in your `config/app.ts` configuration +The `debug` option in your `Path.config('app.ts')` configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the `APP_DEBUG` environment @@ -59,13 +59,13 @@ users. Every error will be logged by default using the `console` driver from `@athenna/logger`. By default, Athenna uses the -`exception` channel of your `config/logging.ts` file to log +`exception` channel of your `Path.config('logging.ts')` file to log all exceptions that happens in your application. :::tip You can change the driver and formatter of `exception` -channel inside `config/logging.ts` file. This way you can +channel inside `Path.config('logging.ts')` file. This way you can send all your error logs to another provider and with a different formatter. @@ -121,7 +121,7 @@ export class PaymentRequiredException extends HttpException { You can ignore an exception from being logged if its status code or the code does not match your requirements. To do so you can add the following configurations to the `logger` -property in your `config/http.ts` configuration file: +property in your `Path.config('http.ts')` configuration file: ```typescript export default { diff --git a/docs/rest-api-application/middlewares.mdx b/docs/rest-api-application/middlewares.mdx index 909033e6..8d9f62a0 100644 --- a/docs/rest-api-application/middlewares.mdx +++ b/docs/rest-api-application/middlewares.mdx @@ -262,7 +262,7 @@ Route.get('/welcome', () => { :::info The requests log created by Athenna when the `logger` -property is true in your `config/http.ts` file are handled +property is true in your `Path.config('http.ts')` file are handled by a terminator middleware! You can see the code [here](https://github.com/AthennaIO/Http/blob/develop/src/kernels/HttpKernel.ts#L93). ::: diff --git a/docs/rest-api-application/rate-limiting.mdx b/docs/rest-api-application/rate-limiting.mdx index c9435aff..033fd576 100644 --- a/docs/rest-api-application/rate-limiting.mdx +++ b/docs/rest-api-application/rate-limiting.mdx @@ -21,7 +21,7 @@ a user can request your application in a given time-frame. Athenna uses the [`@fastify/rate-limit`](https://github.com/fastify/fastify-rate-limit) plugin inside `HttpKernel`. All the configurations that -`@fastify/rate-limit` supports can be set inside `config/http.js` +`@fastify/rate-limit` supports can be set inside `Path.config('http.ts')` file in the `rateLimit` object: ```typescript @@ -43,7 +43,7 @@ export default { In Athenna you can set specific options of rate limit for specific routes. You can also disable the `global` -option of your `rateLimit` configuration in `config/http.js` +option of your `rateLimit` configuration in `Path.config('http.ts')` and set different rules in your routes: ```typescript diff --git a/docs/rest-api-application/routing.mdx b/docs/rest-api-application/routing.mdx index 00f2fc2a..e3b47442 100644 --- a/docs/rest-api-application/routing.mdx +++ b/docs/rest-api-application/routing.mdx @@ -169,13 +169,13 @@ which a browser should permit loading resources. Athenna uses the [`@fastify/cors`](https://github.com/fastify/fastify-cors) plugin inside `HttpKernel`. All the configurations that -`@fastify/cors` supports can be set inside `config/http.ts` +`@fastify/cors` supports can be set inside `Path.config('http.ts')` file in the `cors` object. Cors plugin is registered in your http application by default, but you can remove it uninstalling `@fastify/cors` from your application, or removing the `cors` object key -from your `config/http.ts` file. +from your `Path.config('http.ts')` file. :::tip diff --git a/docs/rest-api-application/swagger.mdx b/docs/rest-api-application/swagger.mdx index 1ccf1e8a..17fbec6b 100644 --- a/docs/rest-api-application/swagger.mdx +++ b/docs/rest-api-application/swagger.mdx @@ -23,9 +23,9 @@ is the root of all awesomeness in Swagger. Athenna uses the [`@fastify/swagger`](https://github.com/fastify/fastify-swagger) and [`@fastify/swagger-ui`](https://github.com/fastify/fastify-swagger-ui) plugins inside `HttpKernel`. All the configurations that `@fastify/swagger` -supports can be set inside `config/http.js` file in the `swagger.configurations` +supports can be set inside `Path.config('http.ts')` file in the `swagger.configurations` object. And all the configurations that `@fastify/swagger-ui` -supports can be set inside `config/http.js` file in the `swagger.ui` object: +supports can be set inside `Path.config('http.ts')` file in the `swagger.ui` object: ```typescript export default { diff --git a/docs/rest-api-application/tracing-requests.mdx b/docs/rest-api-application/tracing-requests.mdx index 77f02883..c01686b1 100644 --- a/docs/rest-api-application/tracing-requests.mdx +++ b/docs/rest-api-application/tracing-requests.mdx @@ -24,7 +24,7 @@ identify bottlenecks and focus on improving performance. Athenna uses the [`cls-rtracer`](https://github.com/puzpuzpuz/cls-rtracer) plugin inside `HttpKernel`. All the configurations that `cls-rtracer` supports can be set inside -`config/http.js` file in the `rTracer` object: +`Path.config('http.ts')` file in the `rTracer` object: ```typescript export default { diff --git a/docs/the-basics/logging.mdx b/docs/the-basics/logging.mdx index 3791855b..451c015d 100644 --- a/docs/the-basics/logging.mdx +++ b/docs/the-basics/logging.mdx @@ -27,7 +27,7 @@ the http requests that your application receives. ## Configuration All the configuration options for your application's logging -behavior are housed in the `config/logging.ts` configuration +behavior are housed in the `Path.config('logging.ts')` configuration file. This file allows you to configure your application's log channels, so be sure to review each of the available channels and their options. We'll review a few common options @@ -39,7 +39,7 @@ Each log channel is powered by a "driver". The driver determines how and where the log message is actually transported. The following log channel drivers are available in every Athenna application. An entry for most of these drivers is already -present in your application's `config/logging.ts` configuration +present in your application's `Path.config('logging.ts')` configuration file, so be sure to review this file to become familiar with its contents: @@ -57,7 +57,7 @@ its contents: Almost all channels doesn't need any additional configuration to work. But some of than need a couple of changes in -`config/logging.ts` file to be able to use. They are `slack`, +`Path.config('logging.ts')` file to be able to use. They are `slack`, `discord` and `telegram`. #### Configuring the Slack channel @@ -157,7 +157,7 @@ import { DriverFactory } from '@athenna/logger' DriverFactory.createDriver('consoleLog', ConsoleLogDriver) ``` -Finally, we can start using our new driver in channels of `config/logging.ts`: +Finally, we can start using our new driver in channels of `Path.config('logging.ts')`: ```typescript channels: { @@ -193,7 +193,7 @@ Log.fatal(message) You may call any of these methods to log a message for the corresponding level. By default, the message will be written to the default log channel as configured by your -`config/logging.ts` configuration file: +`Path.config('logging.ts')` configuration file: ```typescript import { WelcomeService } from '#app/services/WelcomeService' @@ -233,7 +233,7 @@ example configuration that you might see in a production application: Take note of the `level` configuration option present in -`slack` channel of your `config/logging.ts` file: +`slack` channel of your `Path.config('logging.ts')` file: ```typescript channels: { @@ -321,7 +321,7 @@ Log.info(`${chalk.yellow.bold('Hello')} ${chalk.green.italic('World')}!`) It is also possible to set runtime configurations when using the `Log` facade. This way you will never be total -dependent from `config/logging.ts` configuration file. To +dependent from `Path.config('logging.ts')` configuration file. To accomplish this, you may pass a configuration object to the `config` method of Log facade and then call the `channel` method again to set up the configurations for the specified @@ -343,7 +343,7 @@ Each log channel is powered by a "formatter". The formatter determines how the log message is actually formatted. The following log channel formatters are available in every Athenna application. An entry for most of these formatters is -already present in your application's `config/logging.ts` +already present in your application's `Path.config('logging.ts')` configuration file, so be sure to review this file to become familiar with its contents: @@ -409,7 +409,7 @@ FormatterFactory.createFormatter('consoleLog', ConsoleLogFormatter) ``` Finally, we can start using our new formatter in channels -of `config/logging.ts`: +of `Path.config('logging.ts')`: ```typescript channels: { diff --git a/docs/the-basics/views.mdx b/docs/the-basics/views.mdx index 5af3932f..a50df6b9 100644 --- a/docs/the-basics/views.mdx +++ b/docs/the-basics/views.mdx @@ -41,7 +41,7 @@ allow you to easily log values, create "if" statements, iterate over data, and more. Once you have created a view file, eg: `resources/views/welcome.edge`, -you may register your view disk inside `config/view.ts` file: +you may register your view disk inside `Path.config('view.ts')` file: ```typescript import { Path } from '@athenna/common' @@ -184,7 +184,7 @@ time-consuming process, and hence it is recommended to cache the compiled templates in production. You can control the template caching using the `edge.cache` -property inside `config/view.ts` file. Just make sure to set +property inside `Path.config('view.ts')` file. Just make sure to set the value to `true` in the production environment: ```typescript From 24ef91677d4cf972b21534d97374f5e977a58eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 11:32:14 -0300 Subject: [PATCH 2/9] fix(docs): change case in REPL doc --- docs/digging-deeper/repl.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/digging-deeper/repl.mdx b/docs/digging-deeper/repl.mdx index 8615ecb5..4ddbfb08 100644 --- a/docs/digging-deeper/repl.mdx +++ b/docs/digging-deeper/repl.mdx @@ -50,7 +50,7 @@ To import modules inside REPL you need to use dynamic imports: ```javascript { Log } = await import('@athenna/logger') // Destructuring import -helpers = await import('#src/Helpers/index') // Default import +helpers = await import('#app/helpers/index') // Default import ``` :::caution From d2f1bebce76fed236007f995d34d8147f92a5a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 12:12:58 -0300 Subject: [PATCH 3/9] feat(docs): document about E_SIMPLE_CLI --- docs/cli-application/error-handling.mdx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/cli-application/error-handling.mdx b/docs/cli-application/error-handling.mdx index 43325428..a6bf196a 100644 --- a/docs/cli-application/error-handling.mdx +++ b/docs/cli-application/error-handling.mdx @@ -115,6 +115,31 @@ always be considered as a not treated exception. ::: +## Simple exceptions + +When talking about exceptions in Artisan and CLI applications, +we can divide them into two categories: simple exceptions and +the more complex ones. Simple exceptions are exceptions that +when handled by the `ConsoleExceptionHandler` will only log the +exception **message**. The more complex will log the entire exception +including **code, message, help and stack trace**. + +Simple exceptions are recognized by `ConsoleExceptionHandler` by +the `code`. If the code is `E_SIMPLE_CLI`, it will be considered +as a simple exception: + +```typescript title="app/console/exceptions/NotFoundDatabaseException.ts" +import { Exception } from '@athenna/common' + +export class NotFoundDatabaseException extends Exception { + public constructor(databaseName: string) { + const code = 'E_SIMPLE_CLI' 👈 + + super({ code, message: `Database ${databaseName} not found.` }) + } +} +``` + ## Implementing your own exception handler Let's suppose you want to write a custom logic for handling From 5da610b5640f2ec435de7345efc1f3a44b4c0a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 12:30:50 -0300 Subject: [PATCH 4/9] feat(docs): different paths for athennarc --- docs/getting-started/athennarc-file.mdx | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/getting-started/athennarc-file.mdx b/docs/getting-started/athennarc-file.mdx index 365cbfb4..ed235b3d 100644 --- a/docs/getting-started/athennarc-file.mdx +++ b/docs/getting-started/athennarc-file.mdx @@ -42,6 +42,52 @@ also register it inside your `.athennarc.json` file: } ``` +## Custom RC file name + +You can change the name and the path of your RC file or even +create customized ones for each environement (`.athennarc.dev.json`, +`.athennarc.prod.json`). To do that you need to set the new +path to `Ignite.load()` method: + +```typescript filename="bootstrap/dev.ts" +import { Ignite } from '@athenna/core' + +const ignite = await new Ignite().load(import.meta.url, { + athennaRcPath: './bootstrap/athennadevrc.json' 👈 +}) + +await ignite.httpServer() +``` + +:::tip + +Always remember that when using relative paths to set something +in Athenna, you need to use your project root path as reference. + +::: + +## Using RC file in `package.json` + +You can also use the RC file inside `package.json`. By default, +If you don't specify the path of your RC file, and the default +`.athennarc.json` cannot be found in the root path of your application, +Athenna will check if the `athenna` property exists in your `package.json`: + +```json filename="package.json" +{ + "athenna": { + "providers": [ + "@athenna/core/providers/CoreProvider", + "@athenna/http/providers/HttpRouteProvider", + "@athenna/http/providers/HttpServerProvider" + ], + "directories": { + "bootstrap": "bin" + } + } +} +``` + ## The `preloads` property An array of files that will be loaded when your application From 857337a4e3b14a0f065878c5694b320e4473b1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 13:04:20 -0300 Subject: [PATCH 5/9] feat(docs): different paths for env file --- docs/getting-started/athennarc-file.mdx | 5 +++-- docs/getting-started/configuration.mdx | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/getting-started/athennarc-file.mdx b/docs/getting-started/athennarc-file.mdx index ed235b3d..9b7bdba1 100644 --- a/docs/getting-started/athennarc-file.mdx +++ b/docs/getting-started/athennarc-file.mdx @@ -42,7 +42,7 @@ also register it inside your `.athennarc.json` file: } ``` -## Custom RC file name +## Custom RC file path You can change the name and the path of your RC file or even create customized ones for each environement (`.athennarc.dev.json`, @@ -62,7 +62,8 @@ await ignite.httpServer() :::tip Always remember that when using relative paths to set something -in Athenna, you need to use your project root path as reference. +in Athenna, you need to use your project root path as reference, +just like in the example above. ::: diff --git a/docs/getting-started/configuration.mdx b/docs/getting-started/configuration.mdx index 73597a3b..5268f677 100644 --- a/docs/getting-started/configuration.mdx +++ b/docs/getting-started/configuration.mdx @@ -189,6 +189,29 @@ APP_URL=http://${HOST}:${PORT} console.log(Env('APP_URL')) // "http://localhost:3000" ``` +## Custom environment file path + +You can also change the name and the path of your `.env` file. +To do that you need to set the new path to `Ignite.load()` method: + +```typescript filename="bootstrap/dev.ts" +import { Ignite } from '@athenna/core' + +const ignite = await new Ignite().load(import.meta.url, { + envPath: './bootstrap/.env.dev' 👈 +}) + +await ignite.httpServer() +``` + +:::tip + +Always remember that when using relative paths to set something +in Athenna, you need to use your project root path as reference, +just like in the example above. + +::: + ## Configuration files All the configuration files for the Athenna framework are From 358e0d4aa26d3c1ea0bea542e9bfe8ecc292137b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 13:11:23 -0300 Subject: [PATCH 6/9] feat(docs): safe load configs --- docs/getting-started/configuration.mdx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/getting-started/configuration.mdx b/docs/getting-started/configuration.mdx index 5268f677..233973a0 100644 --- a/docs/getting-started/configuration.mdx +++ b/docs/getting-started/configuration.mdx @@ -546,6 +546,29 @@ check [the do your own structure documentation section](https://athenna.io/docs/ for more information about how to create your own project structure. +## Safe loading configuration files + +Athenna got multiple types of applications, while using the framework +you will notice that some times you could end up igniting your application +twice. Let's suppose you are using `./node artisan serve` command to start +your application, this command will first ignite your application by Artisan +and them by the HTTP server. + +This is usually not a problem at all, but depending on how you have created +your environment it could become one. To avoid reloading configuration +files in these situations, you can set the `loadConfigSafe` option as `true` +in `Ignite.load()` method: + +```typescript filename="bootstrap/main.ts" +import { Ignite } from '@athenna/core' + +const ignite = await new Ignite().load(import.meta.url, { + loadConfigSafe: true, 👈 +}) + +await ignite.httpServer() +``` + ## Debug mode The `debug` option in your `Path.config('app.ts')` configuration From 634d0f69f2bfc12cfb8ccc01afc18b90f1317241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 13:15:29 -0300 Subject: [PATCH 7/9] feat(docs): disable boot/shutdown logs --- docs/the-basics/logging.mdx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/the-basics/logging.mdx b/docs/the-basics/logging.mdx index 451c015d..d146b443 100644 --- a/docs/the-basics/logging.mdx +++ b/docs/the-basics/logging.mdx @@ -424,3 +424,23 @@ channels: { } } ``` + +## Disabling boot and shutdown logs + +When your application starts, Athenna creates some logs to help you to track +the application boot process. The same happens when your application is shuting +down. + +If you wish to run your application in silent mode, you can disable this kind +of logs using the `Ignite.load()` method: + +```typescript filename="bootstrap/main.ts" +import { Ignite } from '@athenna/core' + +const ignite = await new Ignite().load(import.meta.url, { + bootLogs: false, 👈 + shutdownLogs: false, 👈 +}) + +await ignite.httpServer() +``` From 12862b99e3928a29ce938353a5473b0855389210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 13:27:32 -0300 Subject: [PATCH 8/9] feat(docs): change route file path --- .../application-lifecycle.mdx | 16 +++++----- .../service-container.mdx | 2 +- .../service-providers.mdx | 2 +- docs/cli-application/error-handling.mdx | 8 ++--- docs/digging-deeper/graceful-shutdown.mdx | 6 ++-- docs/digging-deeper/repl.mdx | 4 +-- docs/getting-started/athennarc-file.mdx | 2 +- docs/getting-started/configuration.mdx | 12 +++---- docs/getting-started/directory-structure.mdx | 8 ++--- docs/getting-started/installation.mdx | 2 +- docs/getting-started/node-script-file.mdx | 2 +- docs/rest-api-application/error-handling.mdx | 12 +++---- docs/rest-api-application/middlewares.mdx | 2 +- docs/rest-api-application/rate-limiting.mdx | 4 +-- docs/rest-api-application/routing.mdx | 27 ++++++++++++++-- docs/rest-api-application/swagger.mdx | 4 +-- .../rest-api-application/tracing-requests.mdx | 31 ++++++++++++++++--- docs/the-basics/logging.mdx | 20 ++++++------ docs/the-basics/views.mdx | 4 +-- 19 files changed, 106 insertions(+), 62 deletions(-) diff --git a/docs/architecture-concepts/application-lifecycle.mdx b/docs/architecture-concepts/application-lifecycle.mdx index 404c4b40..a688dc62 100644 --- a/docs/architecture-concepts/application-lifecycle.mdx +++ b/docs/architecture-concepts/application-lifecycle.mdx @@ -35,7 +35,7 @@ application you are using. Meaning that no matter what is the type of application you are using to build your solution, the explanation bellow is valid for all of them. -The entry point of an Athenna application is the `Path.bootstrap('main.ts')`. +The entry point of an Athenna application is the `Path.bootstrap('main.js')`. The first action taken by Athenna itself is to create an instance of the application and then boot it. @@ -140,7 +140,7 @@ will be fired before executing your command. ### Kernel The Kernel class is responsible by defining some bootstraps that will -be run before reading your `Path.routes('http.ts')` file. These bootstraps +be run before reading your `Path.routes('http.js')` file. These bootstraps configure error handling for requests, tracing and logging, detect the application environment, and perform other tasks that need to be done before the request is actually handled. Typically, these classes handle @@ -168,7 +168,7 @@ implementation code. ::: -Then, you can register your `CustomKernel` in your `Path.bootstrap('main.ts')` +Then, you can register your `CustomKernel` in your `Path.bootstrap('main.js')` file: ```typescript @@ -181,14 +181,14 @@ await ignite.httpServer({ kernelPath: '#app/http/CustomKernel' }) ### Routes -The `Path.routes('http.ts')` file is the entrypoint for all your http requests. +The `Path.routes('http.js')` file is the entrypoint for all your http requests. This file is responsible to create a contract between your client and your application. It Is in here that we define all our routes and the handlers/controllers who will handle the client request. One of the most important service providers in your application is the `HttpRouteProvider`. This service provider adds in the container the -`Route` class instance used inside `Path.routes('http.ts')` file. +`Route` class instance used inside `Path.routes('http.js')` file. When the client request arrives, the server first executes all your global middlewares, then it will execute all your route middlewares. @@ -275,8 +275,8 @@ kernel implementation taking a look at [ConsoleKernel](https://github.com/Athenn ::: -Then, you can register your `CustomKernel` in your `bootstrap/main.ts` or -`bootstrap/artisan.ts` file: +Then, you can register your `CustomKernel` in your `Path.bootstrap('main.js')` or +`Path.bootstrap('artisan.js')` file: ```typescript import { Ignite } from '@athenna/core' @@ -290,7 +290,7 @@ await ignite.artisan({ kernelPath: '#app/http/CustomKernel' }) ### Execution -The `Path.routes('console.ts')` and the `commands` property of `.athennarc.json` file +The `Path.routes('console.js')` and the `commands` property of `.athennarc.json` file is where that we define all ours commands and the handlers who will handle the terminal arguments. diff --git a/docs/architecture-concepts/service-container.mdx b/docs/architecture-concepts/service-container.mdx index d0923f53..a8290ea1 100644 --- a/docs/architecture-concepts/service-container.mdx +++ b/docs/architecture-concepts/service-container.mdx @@ -56,7 +56,7 @@ itself. If you use the `@Service` annotation, you can instruct the container how he should resolve that class, or use the default resolution configurations of the annotation. For example, you may place the following code in your -`Path.routes('http.ts')` file: +`Path.routes('http.js')` file: ```typescript import { Route } from '@athenna/http' diff --git a/docs/architecture-concepts/service-providers.mdx b/docs/architecture-concepts/service-providers.mdx index 9817a546..cfae11d7 100644 --- a/docs/architecture-concepts/service-providers.mdx +++ b/docs/architecture-concepts/service-providers.mdx @@ -173,7 +173,7 @@ The following environments are available by default in Athenna at this moment: - repl - console -You could also create your own environments. In your `bootstrap/main.ts` file +You could also create your own environments. In your `Path.bootstrap('main.js')` file you can add an `environments` option when calling `Ignite.load` method: ```typescript diff --git a/docs/cli-application/error-handling.mdx b/docs/cli-application/error-handling.mdx index a6bf196a..1a87e8eb 100644 --- a/docs/cli-application/error-handling.mdx +++ b/docs/cli-application/error-handling.mdx @@ -62,7 +62,7 @@ bootstrap failure has been found in your application. ## Configuration -The `debug` option in your `Path.config('app.ts')` configuration +The `debug` option in your `Path.config('app.js')` configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the `APP_DEBUG` environment @@ -77,13 +77,13 @@ users. Every error will be logged by default using the `console` driver from `@athenna/logger`. By default, Athenna uses the -`exception` channel of your `Path.config('logging.ts')` file to log +`exception` channel of your `Path.config('logging.js')` file to log all exceptions that happens in your application. :::tip You can change the driver and formatter of `exception` -channel inside `Path.config('logging.ts')` file. This way you can +channel inside `Path.config('logging.js')` file. This way you can send all your error logs to another provider and with a different formatter. @@ -159,7 +159,7 @@ export class Handler extends ConsoleExceptionHandler { Now you need to register your exception handler when bootstrapping your application: -```typescript title="bootstrap/main.ts" +```typescript filename="Path.bootstrap('main.js')" await ignite.artisan(process.argv, { displayName: 'Athenna', exceptionHandlerPath: '#app/console/exceptions/Handler', 👈 diff --git a/docs/digging-deeper/graceful-shutdown.mdx b/docs/digging-deeper/graceful-shutdown.mdx index 7b7184c2..553bb793 100644 --- a/docs/digging-deeper/graceful-shutdown.mdx +++ b/docs/digging-deeper/graceful-shutdown.mdx @@ -105,9 +105,9 @@ Node.js supports registering as many as signals event listeners you want, this means that you can use the default `SIGINT` and `SIGTERM` listeners of Athenna and also create your own. We recommend doing this implementation in the bootstrap -file of your like application, like `bootstrap/main.ts`: +file of your like application: -```typescript +```typescript filename="Path.bootstrap('main.js')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url) @@ -125,7 +125,7 @@ process.on('SIGTERM', () => { If you wish to remove or change the default listeners of Athenna, or also listen to new signals, you can create -the `signals` property in the `Path.config('app.ts')` +the `signals` property in the `Path.config('app.js')` file: ```typescript diff --git a/docs/digging-deeper/repl.mdx b/docs/digging-deeper/repl.mdx index 4ddbfb08..274597d7 100644 --- a/docs/digging-deeper/repl.mdx +++ b/docs/digging-deeper/repl.mdx @@ -40,7 +40,7 @@ run the Artisan command: :::info When running this command, Athenna will use the -`Path.bootstrap('repl.ts')` file to execute your session. +`Path.bootstrap('repl.js')` file to execute your session. ::: @@ -72,7 +72,7 @@ commands available. You can pre-import modules in your REPL session to avoid keep importing them everytime inside your REPL session. You can do that -in your `Path.bootstrap('repl.ts')` file: +in your `Path.bootstrap('repl.js')` file: ```typescript import { Ignite } from '@athenna/core' diff --git a/docs/getting-started/athennarc-file.mdx b/docs/getting-started/athennarc-file.mdx index 9b7bdba1..efcea1a1 100644 --- a/docs/getting-started/athennarc-file.mdx +++ b/docs/getting-started/athennarc-file.mdx @@ -49,7 +49,7 @@ create customized ones for each environement (`.athennarc.dev.json`, `.athennarc.prod.json`). To do that you need to set the new path to `Ignite.load()` method: -```typescript filename="bootstrap/dev.ts" +```typescript filename="Path.bootstrap('dev.js')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url, { diff --git a/docs/getting-started/configuration.mdx b/docs/getting-started/configuration.mdx index 233973a0..52a9db89 100644 --- a/docs/getting-started/configuration.mdx +++ b/docs/getting-started/configuration.mdx @@ -194,7 +194,7 @@ console.log(Env('APP_URL')) // "http://localhost:3000" You can also change the name and the path of your `.env` file. To do that you need to set the new path to `Ignite.load()` method: -```typescript filename="bootstrap/dev.ts" +```typescript filename="Path.bootstrap('dev.js')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url, { @@ -361,7 +361,7 @@ Config.set('app.name', builders.functionCall('Env', ['MY_APP_NAME'])) await Config.rewrite('app') ``` -The example above will produce the following code in `Path.config('app.ts')`: +The example above will produce the following code in `Path.config('app.js')`: ```typescript export default { @@ -445,7 +445,7 @@ file path: import { Path } from '@athenna/common' import { Config } from '@athenna/config' -await Config.load(Path.stubs('config/test.ts')) +await Config.load(Path.stubs('config/test.js')) console.log(Config.get('test')) // { ... } ``` @@ -459,7 +459,7 @@ is not defined: import { Path } from '@athenna/common' import { Config } from '@athenna/config' -await Config.safeLoad(Path.stubs('config/app.ts')) +await Config.safeLoad(Path.stubs('config/app.js')) ``` #### `Config.loadAll()` @@ -559,7 +559,7 @@ your environment it could become one. To avoid reloading configuration files in these situations, you can set the `loadConfigSafe` option as `true` in `Ignite.load()` method: -```typescript filename="bootstrap/main.ts" +```typescript filename="Path.bootstrap('main.js')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url, { @@ -571,7 +571,7 @@ await ignite.httpServer() ## Debug mode -The `debug` option in your `Path.config('app.ts')` configuration +The `debug` option in your `Path.config('app.js')` configuration file determines how much information about your application is actually displayed to you and for who is going to consume your application. By default, this option is set to respect diff --git a/docs/getting-started/directory-structure.mdx b/docs/getting-started/directory-structure.mdx index 1b7b7f2e..9f2e87d7 100644 --- a/docs/getting-started/directory-structure.mdx +++ b/docs/getting-started/directory-structure.mdx @@ -126,7 +126,7 @@ command. If your test file name does not end with `Test`, it will be ignored and the test class will not run. But, you can customize this behavior in the configure function of [Japa](https://japa.dev/docs) -inside your `bootstrap/test.ts` file. +inside your `Path.bootstrap('test.js')` file. ::: @@ -144,16 +144,16 @@ create the project: There are some files in your project that are crucial to keep in certain places. Let's analyze some of them: -- The `bootstrap/main.ts` file is the entry point of the +- The `Path.bootstrap('main.js')` file is the entry point of the `./node artisan serve` command. Every time that you run this command, Athenna will use this file to run your application. -- The `bootstrap/artisan.ts` file is the entry point of the +- The `Path.bootstrap('artisan.js')` file is the entry point of the `./node artisan` script. You can check how this works in the [node script file documentation section](https://athenna.io/docs/getting-started/node-script-file). - The `config` path is where you are going to set up your configuration files. You can learn more about configuration files at [the configuration documentation section](https://athenna.io/docs/getting-started/configuration). -- The `Path.routes('http.ts')` file is where you are going to register +- The `Path.routes('http.js')` file is where you are going to register your Http server routes. Athenna is a framework with a lot of opinions, with predefined diff --git a/docs/getting-started/installation.mdx b/docs/getting-started/installation.mdx index 18ad9c8c..c41eeb00 100644 --- a/docs/getting-started/installation.mdx +++ b/docs/getting-started/installation.mdx @@ -70,5 +70,5 @@ In your project root, run the following command: - The `watch` flag is meant to watch the file system for changes and restart your application automatically when doing some change on it. -- The `serve` command will look up for your `bootstrap/main.js` +- The `serve` command will look up for your `Path.bootstrap('main.js')` file to bootstrap your application with predefined configurations. diff --git a/docs/getting-started/node-script-file.mdx b/docs/getting-started/node-script-file.mdx index ce2a56a2..fbed839a 100644 --- a/docs/getting-started/node-script-file.mdx +++ b/docs/getting-started/node-script-file.mdx @@ -96,7 +96,7 @@ when bootstrapping your application. If you take a look at the content of the node script file, you will see that we are using [sed](https://www.geeksforgeeks.org/sed-command-linux-set-2/) command to replace the `artisan` argument with the path to -`bootstrap/artisan.ts` file. +`Path.bootstrap('main.js')` file. This is a tricky implementation that will allow you to call your artisan commands without the need to add the full path diff --git a/docs/rest-api-application/error-handling.mdx b/docs/rest-api-application/error-handling.mdx index 65826265..9924b9e3 100644 --- a/docs/rest-api-application/error-handling.mdx +++ b/docs/rest-api-application/error-handling.mdx @@ -22,7 +22,7 @@ This documentation will cover about error handling in the **REST API** application, which means that only errors that happens inside routes and bellow that will be handled: -```typescript title="Path.routes('http.ts')" +```typescript title="Path.routes('http.js')" import { Route } from '@athenna/http' // If AppController.show throws, HttpExceptionHandler will handle it 👈 @@ -44,7 +44,7 @@ bootstrap failure has been found in your application. ## Configuration -The `debug` option in your `Path.config('app.ts')` configuration +The `debug` option in your `Path.config('app.js')` configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the `APP_DEBUG` environment @@ -59,13 +59,13 @@ users. Every error will be logged by default using the `console` driver from `@athenna/logger`. By default, Athenna uses the -`exception` channel of your `Path.config('logging.ts')` file to log +`exception` channel of your `Path.config('logging.js')` file to log all exceptions that happens in your application. :::tip You can change the driver and formatter of `exception` -channel inside `Path.config('logging.ts')` file. This way you can +channel inside `Path.config('logging.js')` file. This way you can send all your error logs to another provider and with a different formatter. @@ -121,7 +121,7 @@ export class PaymentRequiredException extends HttpException { You can ignore an exception from being logged if its status code or the code does not match your requirements. To do so you can add the following configurations to the `logger` -property in your `Path.config('http.ts')` configuration file: +property in your `Path.config('http.js')` configuration file: ```typescript export default { @@ -182,7 +182,7 @@ export class Handler extends HttpExceptionHandler { Now you need to register your exception handler when bootstrapping your application: -```typescript title="bootstrap/main.ts" +```typescript filename="Path.bootstrap('main.js')" await ignite.httpServer({ exceptionHandlerPath: '#app/http/exceptions/Handler', 👈 }) diff --git a/docs/rest-api-application/middlewares.mdx b/docs/rest-api-application/middlewares.mdx index 8d9f62a0..5cf7bf2a 100644 --- a/docs/rest-api-application/middlewares.mdx +++ b/docs/rest-api-application/middlewares.mdx @@ -262,7 +262,7 @@ Route.get('/welcome', () => { :::info The requests log created by Athenna when the `logger` -property is true in your `Path.config('http.ts')` file are handled +property is true in your `Path.config('http.js')` file are handled by a terminator middleware! You can see the code [here](https://github.com/AthennaIO/Http/blob/develop/src/kernels/HttpKernel.ts#L93). ::: diff --git a/docs/rest-api-application/rate-limiting.mdx b/docs/rest-api-application/rate-limiting.mdx index 033fd576..fc580f5b 100644 --- a/docs/rest-api-application/rate-limiting.mdx +++ b/docs/rest-api-application/rate-limiting.mdx @@ -21,7 +21,7 @@ a user can request your application in a given time-frame. Athenna uses the [`@fastify/rate-limit`](https://github.com/fastify/fastify-rate-limit) plugin inside `HttpKernel`. All the configurations that -`@fastify/rate-limit` supports can be set inside `Path.config('http.ts')` +`@fastify/rate-limit` supports can be set inside `Path.config('http.js')` file in the `rateLimit` object: ```typescript @@ -43,7 +43,7 @@ export default { In Athenna you can set specific options of rate limit for specific routes. You can also disable the `global` -option of your `rateLimit` configuration in `Path.config('http.ts')` +option of your `rateLimit` configuration in `Path.config('http.js')` and set different rules in your routes: ```typescript diff --git a/docs/rest-api-application/routing.mdx b/docs/rest-api-application/routing.mdx index e3b47442..24069fc3 100644 --- a/docs/rest-api-application/routing.mdx +++ b/docs/rest-api-application/routing.mdx @@ -169,13 +169,13 @@ which a browser should permit loading resources. Athenna uses the [`@fastify/cors`](https://github.com/fastify/fastify-cors) plugin inside `HttpKernel`. All the configurations that -`@fastify/cors` supports can be set inside `Path.config('http.ts')` +`@fastify/cors` supports can be set inside `Path.config('http.js')` file in the `cors` object. Cors plugin is registered in your http application by default, but you can remove it uninstalling `@fastify/cors` from your application, or removing the `cors` object key -from your `Path.config('http.ts')` file. +from your `Path.config('http.js')` file. :::tip @@ -183,3 +183,26 @@ For more information on CORS and CORS headers, please consult the [MDN web documentation on CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). ::: + +## Custom route file path + +You can change the name and the path of your `Path.route('http.js')` file. +To do that you need to set the new path to `Ignite.httpServer()` method: + +```typescript filename="Path.bootstrap('dev.js')" +import { Ignite } from '@athenna/core' + +const ignite = await new Ignite().load(import.meta.url) + +await ignite.httpServer({ + routePath: './bootstrap/routes/http-dev.js' 👈 +}) +``` + +:::tip + +Always remember that when using relative paths to set something +in Athenna, you need to use your project root path as reference, +just like in the example above. + +::: diff --git a/docs/rest-api-application/swagger.mdx b/docs/rest-api-application/swagger.mdx index 17fbec6b..1f583b5c 100644 --- a/docs/rest-api-application/swagger.mdx +++ b/docs/rest-api-application/swagger.mdx @@ -23,9 +23,9 @@ is the root of all awesomeness in Swagger. Athenna uses the [`@fastify/swagger`](https://github.com/fastify/fastify-swagger) and [`@fastify/swagger-ui`](https://github.com/fastify/fastify-swagger-ui) plugins inside `HttpKernel`. All the configurations that `@fastify/swagger` -supports can be set inside `Path.config('http.ts')` file in the `swagger.configurations` +supports can be set inside `Path.config('http.js')` file in the `swagger.configurations` object. And all the configurations that `@fastify/swagger-ui` -supports can be set inside `Path.config('http.ts')` file in the `swagger.ui` object: +supports can be set inside `Path.config('http.js')` file in the `swagger.ui` object: ```typescript export default { diff --git a/docs/rest-api-application/tracing-requests.mdx b/docs/rest-api-application/tracing-requests.mdx index c01686b1..251ebed2 100644 --- a/docs/rest-api-application/tracing-requests.mdx +++ b/docs/rest-api-application/tracing-requests.mdx @@ -24,7 +24,7 @@ identify bottlenecks and focus on improving performance. Athenna uses the [`cls-rtracer`](https://github.com/puzpuzpuz/cls-rtracer) plugin inside `HttpKernel`. All the configurations that `cls-rtracer` supports can be set inside -`Path.config('http.ts')` file in the `rTracer` object: +`Path.config('http.js')` file in the `rTracer` object: ```typescript export default { @@ -65,11 +65,32 @@ ID for you. ## Disabling tracer The `HttpKernel` class will automatically disable the -plugin registration if `http.trace` is set to `false` -or if the package does not exist, so to disable tracer -in Athenna you need to remove the `cls-rtracer` package -from your application: +plugin registration if the package does not exist, so +to disable tracer in Athenna you need to remove the +`cls-rtracer` package from your application: ```shell npm remove cls-rtracer ``` + +You can also disable the tracer by setting `http.trace` to `false`: + +```typescript filename="Path.config('http.js')" +export default { + trace: false, +} +``` + +Or by setting the `tracer` option as `false` when booting the +server in `Ignite.httpServer()` method: + +```typescript filename="Path.bootstrap('main.js')" +import { Ignite } from '@athenna/core' + +const ignite = await new Ignite().load(import.meta.url) + +await ignite.httpServer({ + trace: false, 👈 +}) +``` + diff --git a/docs/the-basics/logging.mdx b/docs/the-basics/logging.mdx index d146b443..0c778fc1 100644 --- a/docs/the-basics/logging.mdx +++ b/docs/the-basics/logging.mdx @@ -27,7 +27,7 @@ the http requests that your application receives. ## Configuration All the configuration options for your application's logging -behavior are housed in the `Path.config('logging.ts')` configuration +behavior are housed in the `Path.config('logging.js')` configuration file. This file allows you to configure your application's log channels, so be sure to review each of the available channels and their options. We'll review a few common options @@ -39,7 +39,7 @@ Each log channel is powered by a "driver". The driver determines how and where the log message is actually transported. The following log channel drivers are available in every Athenna application. An entry for most of these drivers is already -present in your application's `Path.config('logging.ts')` configuration +present in your application's `Path.config('logging.js')` configuration file, so be sure to review this file to become familiar with its contents: @@ -57,7 +57,7 @@ its contents: Almost all channels doesn't need any additional configuration to work. But some of than need a couple of changes in -`Path.config('logging.ts')` file to be able to use. They are `slack`, +`Path.config('logging.js')` file to be able to use. They are `slack`, `discord` and `telegram`. #### Configuring the Slack channel @@ -157,7 +157,7 @@ import { DriverFactory } from '@athenna/logger' DriverFactory.createDriver('consoleLog', ConsoleLogDriver) ``` -Finally, we can start using our new driver in channels of `Path.config('logging.ts')`: +Finally, we can start using our new driver in channels of `Path.config('logging.js')`: ```typescript channels: { @@ -193,7 +193,7 @@ Log.fatal(message) You may call any of these methods to log a message for the corresponding level. By default, the message will be written to the default log channel as configured by your -`Path.config('logging.ts')` configuration file: +`Path.config('logging.js')` configuration file: ```typescript import { WelcomeService } from '#app/services/WelcomeService' @@ -233,7 +233,7 @@ example configuration that you might see in a production application: Take note of the `level` configuration option present in -`slack` channel of your `Path.config('logging.ts')` file: +`slack` channel of your `Path.config('logging.js')` file: ```typescript channels: { @@ -321,7 +321,7 @@ Log.info(`${chalk.yellow.bold('Hello')} ${chalk.green.italic('World')}!`) It is also possible to set runtime configurations when using the `Log` facade. This way you will never be total -dependent from `Path.config('logging.ts')` configuration file. To +dependent from `Path.config('logging.js')` configuration file. To accomplish this, you may pass a configuration object to the `config` method of Log facade and then call the `channel` method again to set up the configurations for the specified @@ -343,7 +343,7 @@ Each log channel is powered by a "formatter". The formatter determines how the log message is actually formatted. The following log channel formatters are available in every Athenna application. An entry for most of these formatters is -already present in your application's `Path.config('logging.ts')` +already present in your application's `Path.config('logging.js')` configuration file, so be sure to review this file to become familiar with its contents: @@ -409,7 +409,7 @@ FormatterFactory.createFormatter('consoleLog', ConsoleLogFormatter) ``` Finally, we can start using our new formatter in channels -of `Path.config('logging.ts')`: +of `Path.config('logging.js')`: ```typescript channels: { @@ -434,7 +434,7 @@ down. If you wish to run your application in silent mode, you can disable this kind of logs using the `Ignite.load()` method: -```typescript filename="bootstrap/main.ts" +```typescript filename="Path.bootstrap('main.js')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url, { diff --git a/docs/the-basics/views.mdx b/docs/the-basics/views.mdx index a50df6b9..8d31e773 100644 --- a/docs/the-basics/views.mdx +++ b/docs/the-basics/views.mdx @@ -41,7 +41,7 @@ allow you to easily log values, create "if" statements, iterate over data, and more. Once you have created a view file, eg: `resources/views/welcome.edge`, -you may register your view disk inside `Path.config('view.ts')` file: +you may register your view disk inside `Path.config('view.js')` file: ```typescript import { Path } from '@athenna/common' @@ -184,7 +184,7 @@ time-consuming process, and hence it is recommended to cache the compiled templates in production. You can control the template caching using the `edge.cache` -property inside `Path.config('view.ts')` file. Just make sure to set +property inside `Path.config('view.js')` file. Just make sure to set the value to `true` in the production environment: ```typescript From ee43b4186686874d1ce9a1738cb3909f91d9c200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Mon, 14 Aug 2023 13:46:17 -0300 Subject: [PATCH 9/9] feat(docs): improve examples --- .../application-lifecycle.mdx | 33 ++++++++-------- .../service-container.mdx | 2 +- .../service-providers.mdx | 2 +- docs/cli-application/error-handling.mdx | 14 +++---- docs/cli-application/running.mdx | 38 +++++++++++++++++++ docs/digging-deeper/graceful-shutdown.mdx | 4 +- docs/digging-deeper/repl.mdx | 4 +- docs/getting-started/athennarc-file.mdx | 8 ++-- docs/getting-started/configuration.mdx | 14 +++---- docs/getting-started/directory-structure.mdx | 16 ++++---- docs/getting-started/installation.mdx | 2 +- docs/getting-started/node-script-file.mdx | 2 +- docs/rest-api-application/error-handling.mdx | 14 +++---- docs/rest-api-application/middlewares.mdx | 2 +- docs/rest-api-application/rate-limiting.mdx | 4 +- docs/rest-api-application/routing.mdx | 8 ++-- docs/rest-api-application/swagger.mdx | 4 +- .../rest-api-application/tracing-requests.mdx | 6 +-- docs/the-basics/logging.mdx | 22 +++++------ docs/the-basics/views.mdx | 4 +- 20 files changed, 121 insertions(+), 82 deletions(-) diff --git a/docs/architecture-concepts/application-lifecycle.mdx b/docs/architecture-concepts/application-lifecycle.mdx index a688dc62..22996356 100644 --- a/docs/architecture-concepts/application-lifecycle.mdx +++ b/docs/architecture-concepts/application-lifecycle.mdx @@ -35,7 +35,7 @@ application you are using. Meaning that no matter what is the type of application you are using to build your solution, the explanation bellow is valid for all of them. -The entry point of an Athenna application is the `Path.bootstrap('main.js')`. +The entry point of an Athenna application is the `Path.bootstrap('main.ts')`. The first action taken by Athenna itself is to create an instance of the application and then boot it. @@ -118,10 +118,11 @@ in the `.athennarc.json` in the `preloads` array. :::note The process of firing the Athenna foundation is triggered by the -`Ignite.fire` method. But if you check your `main.ts` entrypoint file, -you will see that this method is not called directly. The reason for -this is that this method is called internally depending on the type of -application you are using. Let's cover some examples bellow: +`Ignite::fire()` static method. But if you check your `Path.bootstrap('main.ts')` +entrypoint file, you will see that this method is not called directly. +The reason for this is that this method is called internally depending +on the type of application you are using. Let's cover some examples +bellow: - The `REST API` application needs to fire the foundation first because it depends on service providers to register your controllers, services, @@ -140,7 +141,7 @@ will be fired before executing your command. ### Kernel The Kernel class is responsible by defining some bootstraps that will -be run before reading your `Path.routes('http.js')` file. These bootstraps +be run before reading your `Path.routes('http.ts')` file. These bootstraps configure error handling for requests, tracing and logging, detect the application environment, and perform other tasks that need to be done before the request is actually handled. Typically, these classes handle @@ -168,7 +169,7 @@ implementation code. ::: -Then, you can register your `CustomKernel` in your `Path.bootstrap('main.js')` +Then, you can register your `CustomKernel` in your `Path.bootstrap('main.ts')` file: ```typescript @@ -181,14 +182,14 @@ await ignite.httpServer({ kernelPath: '#app/http/CustomKernel' }) ### Routes -The `Path.routes('http.js')` file is the entrypoint for all your http requests. +The `Path.routes('http.ts')` file is the entrypoint for all your http requests. This file is responsible to create a contract between your client and your application. It Is in here that we define all our routes and the handlers/controllers who will handle the client request. One of the most important service providers in your application is the `HttpRouteProvider`. This service provider adds in the container the -`Route` class instance used inside `Path.routes('http.js')` file. +`Route` class instance used inside `Path.routes('http.ts')` file. When the client request arrives, the server first executes all your global middlewares, then it will execute all your route middlewares. @@ -275,8 +276,8 @@ kernel implementation taking a look at [ConsoleKernel](https://github.com/Athenn ::: -Then, you can register your `CustomKernel` in your `Path.bootstrap('main.js')` or -`Path.bootstrap('artisan.js')` file: +Then, you can register your `CustomKernel` in your +`Path.bootstrap('main.ts')` or `Path.bootstrap('artisan.ts')` file: ```typescript import { Ignite } from '@athenna/core' @@ -290,9 +291,9 @@ await ignite.artisan({ kernelPath: '#app/http/CustomKernel' }) ### Execution -The `Path.routes('console.js')` and the `commands` property of `.athennarc.json` file -is where that we define all ours commands and the handlers who will handle -the terminal arguments. +The `Path.routes('console.ts')` and the `commands` property of +`.athennarc.json` file is where that we define all ours commands +and the handlers who will handle the terminal arguments. When the terminal arguments arrive, the application will be bootstrapped based on the command that you are asking to execute. Let's suppose we have @@ -318,10 +319,10 @@ command and execute it: ```mermaid flowchart LR terminalCommand(("Terminal Command")) - igniteLoad{"Ignite.load()"} + igniteLoad{"Ignite::load()"} consoleKernel{"ConsoleKernel"} loadAppEqualsTrue{"loadApp === true"} - igniteFire{"Ignite.fire()"} + igniteFire{"Ignite::fire()"} defineArgsAndFlags{"Define arguments and flags"} commandHandler("Command Handler") diff --git a/docs/architecture-concepts/service-container.mdx b/docs/architecture-concepts/service-container.mdx index a8290ea1..d0923f53 100644 --- a/docs/architecture-concepts/service-container.mdx +++ b/docs/architecture-concepts/service-container.mdx @@ -56,7 +56,7 @@ itself. If you use the `@Service` annotation, you can instruct the container how he should resolve that class, or use the default resolution configurations of the annotation. For example, you may place the following code in your -`Path.routes('http.js')` file: +`Path.routes('http.ts')` file: ```typescript import { Route } from '@athenna/http' diff --git a/docs/architecture-concepts/service-providers.mdx b/docs/architecture-concepts/service-providers.mdx index cfae11d7..16409e26 100644 --- a/docs/architecture-concepts/service-providers.mdx +++ b/docs/architecture-concepts/service-providers.mdx @@ -173,7 +173,7 @@ The following environments are available by default in Athenna at this moment: - repl - console -You could also create your own environments. In your `Path.bootstrap('main.js')` file +You could also create your own environments. In your `Path.bootstrap('main.ts')` file you can add an `environments` option when calling `Ignite.load` method: ```typescript diff --git a/docs/cli-application/error-handling.mdx b/docs/cli-application/error-handling.mdx index 1a87e8eb..903c82d2 100644 --- a/docs/cli-application/error-handling.mdx +++ b/docs/cli-application/error-handling.mdx @@ -27,7 +27,7 @@ This documentation will cover about error handling in the **CLI** application, which means that only errors that happens inside the `handle()` method of commands and bellow that will be handled: -```typescript title="app/console/commands/AppCommand.ts" +```typescript title="app/console/commands/AppCommand.js" import { BaseCommand } from '@athenna/artisan' import { AppService } from '#app/services/AppService' @@ -62,7 +62,7 @@ bootstrap failure has been found in your application. ## Configuration -The `debug` option in your `Path.config('app.js')` configuration +The `debug` option in your `Path.config('app.ts')` configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the `APP_DEBUG` environment @@ -77,13 +77,13 @@ users. Every error will be logged by default using the `console` driver from `@athenna/logger`. By default, Athenna uses the -`exception` channel of your `Path.config('logging.js')` file to log +`exception` channel of your `Path.config('logging.ts')` file to log all exceptions that happens in your application. :::tip You can change the driver and formatter of `exception` -channel inside `Path.config('logging.js')` file. This way you can +channel inside `Path.config('logging.ts')` file. This way you can send all your error logs to another provider and with a different formatter. @@ -128,7 +128,7 @@ Simple exceptions are recognized by `ConsoleExceptionHandler` by the `code`. If the code is `E_SIMPLE_CLI`, it will be considered as a simple exception: -```typescript title="app/console/exceptions/NotFoundDatabaseException.ts" +```typescript title="app/console/exceptions/NotFoundDatabaseException.js" import { Exception } from '@athenna/common' export class NotFoundDatabaseException extends Exception { @@ -146,7 +146,7 @@ Let's suppose you want to write a custom logic for handling your exceptions. You can do so by creating your own exception handler: -```typescript title="app/console/exceptions/Handler.ts" +```typescript title="app/console/exceptions/Handler.js" import { ConsoleExceptionHandler } from '@athenna/artisan' export class Handler extends ConsoleExceptionHandler { @@ -159,7 +159,7 @@ export class Handler extends ConsoleExceptionHandler { Now you need to register your exception handler when bootstrapping your application: -```typescript filename="Path.bootstrap('main.js')" +```typescript title="Path.bootstrap('main.ts')" await ignite.artisan(process.argv, { displayName: 'Athenna', exceptionHandlerPath: '#app/console/exceptions/Handler', 👈 diff --git a/docs/cli-application/running.mdx b/docs/cli-application/running.mdx index 865c59a0..ab2a662b 100644 --- a/docs/cli-application/running.mdx +++ b/docs/cli-application/running.mdx @@ -58,3 +58,41 @@ And now the `yourCliCommand` will exist in your actual Node.js version: ```shell yourCliCommand --help ``` + +## Display CLI name + +When running your CLI without any option and command, the display +name will be rendered in the terminal using +[`chalk-rainbow`](https://www.npmjs.com/package/chalk-rainbow) +and [`figlet`](https://www.npmjs.com/package/figlet). + +By default Artisan always display the `Artisan` name, but you can +change it for your own display name by setting the `displayName` +property in `Ignite.artisan()` method: + +```typescript title="Path.bootstrap('main.ts')" +import { Ignite } from '@athenna/core' + +const ignite = await new Ignite().load(import.meta.url) + +await ignite.artisan({ + displayName: 'Your CLI Command', 👈 +}) +``` + +:::tip + +If you wish to disable the display name, just set the `displayName` +as `null`: + +```typescript title="Path.bootstrap('main.ts')" +import { Ignite } from '@athenna/core' + +const ignite = await new Ignite().load(import.meta.url) + +await ignite.artisan({ + displayName: null, 👈 +}) +``` + +::: diff --git a/docs/digging-deeper/graceful-shutdown.mdx b/docs/digging-deeper/graceful-shutdown.mdx index 553bb793..47d5ffc2 100644 --- a/docs/digging-deeper/graceful-shutdown.mdx +++ b/docs/digging-deeper/graceful-shutdown.mdx @@ -107,7 +107,7 @@ listeners you want, this means that you can use the default your own. We recommend doing this implementation in the bootstrap file of your like application: -```typescript filename="Path.bootstrap('main.js')" +```typescript title="Path.bootstrap('main.ts')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url) @@ -125,7 +125,7 @@ process.on('SIGTERM', () => { If you wish to remove or change the default listeners of Athenna, or also listen to new signals, you can create -the `signals` property in the `Path.config('app.js')` +the `signals` property in the `Path.config('app.ts')` file: ```typescript diff --git a/docs/digging-deeper/repl.mdx b/docs/digging-deeper/repl.mdx index 274597d7..4ddbfb08 100644 --- a/docs/digging-deeper/repl.mdx +++ b/docs/digging-deeper/repl.mdx @@ -40,7 +40,7 @@ run the Artisan command: :::info When running this command, Athenna will use the -`Path.bootstrap('repl.js')` file to execute your session. +`Path.bootstrap('repl.ts')` file to execute your session. ::: @@ -72,7 +72,7 @@ commands available. You can pre-import modules in your REPL session to avoid keep importing them everytime inside your REPL session. You can do that -in your `Path.bootstrap('repl.js')` file: +in your `Path.bootstrap('repl.ts')` file: ```typescript import { Ignite } from '@athenna/core' diff --git a/docs/getting-started/athennarc-file.mdx b/docs/getting-started/athennarc-file.mdx index efcea1a1..8deac47f 100644 --- a/docs/getting-started/athennarc-file.mdx +++ b/docs/getting-started/athennarc-file.mdx @@ -47,9 +47,9 @@ also register it inside your `.athennarc.json` file: You can change the name and the path of your RC file or even create customized ones for each environement (`.athennarc.dev.json`, `.athennarc.prod.json`). To do that you need to set the new -path to `Ignite.load()` method: +path to `Ignite::load()` static method: -```typescript filename="Path.bootstrap('dev.js')" +```typescript title="Path.bootstrap('dev.ts')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url, { @@ -74,7 +74,7 @@ If you don't specify the path of your RC file, and the default `.athennarc.json` cannot be found in the root path of your application, Athenna will check if the `athenna` property exists in your `package.json`: -```json filename="package.json" +```json title="package.json" { "athenna": { "providers": [ @@ -96,7 +96,7 @@ is bootstrapping. The files are loaded after booting the service providers. You can do anything you want in preload files. Check the example bellow: -```typescript filename="say-hello.js" +```typescript title="say-hello.js" import { Log } from '@athenna/logger' import { Config } from '@athenna/core' diff --git a/docs/getting-started/configuration.mdx b/docs/getting-started/configuration.mdx index 52a9db89..225beb33 100644 --- a/docs/getting-started/configuration.mdx +++ b/docs/getting-started/configuration.mdx @@ -192,9 +192,9 @@ console.log(Env('APP_URL')) // "http://localhost:3000" ## Custom environment file path You can also change the name and the path of your `.env` file. -To do that you need to set the new path to `Ignite.load()` method: +To do that you need to set the new path to `Ignite::load()` static method: -```typescript filename="Path.bootstrap('dev.js')" +```typescript title="Path.bootstrap('dev.ts')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url, { @@ -361,7 +361,7 @@ Config.set('app.name', builders.functionCall('Env', ['MY_APP_NAME'])) await Config.rewrite('app') ``` -The example above will produce the following code in `Path.config('app.js')`: +The example above will produce the following code in `Path.config('app.ts')`: ```typescript export default { @@ -445,7 +445,7 @@ file path: import { Path } from '@athenna/common' import { Config } from '@athenna/config' -await Config.load(Path.stubs('config/test.js')) +await Config.load(Path.stubs('config/test.ts')) console.log(Config.get('test')) // { ... } ``` @@ -557,9 +557,9 @@ and them by the HTTP server. This is usually not a problem at all, but depending on how you have created your environment it could become one. To avoid reloading configuration files in these situations, you can set the `loadConfigSafe` option as `true` -in `Ignite.load()` method: +in `Ignite::load()` static method: -```typescript filename="Path.bootstrap('main.js')" +```typescript title="Path.bootstrap('main.ts')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url, { @@ -571,7 +571,7 @@ await ignite.httpServer() ## Debug mode -The `debug` option in your `Path.config('app.js')` configuration +The `debug` option in your `Path.config('app.ts')` configuration file determines how much information about your application is actually displayed to you and for who is going to consume your application. By default, this option is set to respect diff --git a/docs/getting-started/directory-structure.mdx b/docs/getting-started/directory-structure.mdx index 9f2e87d7..b75205f9 100644 --- a/docs/getting-started/directory-structure.mdx +++ b/docs/getting-started/directory-structure.mdx @@ -34,7 +34,7 @@ the classes in your application will be in this directory. ### The bootstrap directory The `bootstrap` directory contains all of your application's -bootstrap files. It's here that Athenna holds the `main.ts` +bootstrap files. It's here that Athenna holds the `main.js` file that bootstrap the application using the `Ignite` class. ### The config directory @@ -71,17 +71,17 @@ The `routes` directory contains all the route definitions for your application. By default, several route files are included with Athenna: -- The `http.ts` file is where you will define the entry +- The `http.js` file is where you will define the entry point of your api using the Route facade that is provided by the HttpRouteProvider. -- The `console.ts` file is where you will define the entry +- The `console.js` file is where you will define the entry point of your commands using the Artisan facade that is provided by the ArtisanProvider. :::important As you may have noticed your project does not have the -`console.ts` file. We only recommend using this file when +`console.js` file. We only recommend using this file when you don't want to use TypeScript in your application or when you want to add some personalized option of [commander](https://www.npmjs.com/package/commander) to your command. Check the example: @@ -126,7 +126,7 @@ command. If your test file name does not end with `Test`, it will be ignored and the test class will not run. But, you can customize this behavior in the configure function of [Japa](https://japa.dev/docs) -inside your `Path.bootstrap('test.js')` file. +inside your `Path.bootstrap('test.ts')` file. ::: @@ -144,16 +144,16 @@ create the project: There are some files in your project that are crucial to keep in certain places. Let's analyze some of them: -- The `Path.bootstrap('main.js')` file is the entry point of the +- The `Path.bootstrap('main.ts')` file is the entry point of the `./node artisan serve` command. Every time that you run this command, Athenna will use this file to run your application. -- The `Path.bootstrap('artisan.js')` file is the entry point of the +- The `Path.bootstrap('artisan.ts')` file is the entry point of the `./node artisan` script. You can check how this works in the [node script file documentation section](https://athenna.io/docs/getting-started/node-script-file). - The `config` path is where you are going to set up your configuration files. You can learn more about configuration files at [the configuration documentation section](https://athenna.io/docs/getting-started/configuration). -- The `Path.routes('http.js')` file is where you are going to register +- The `Path.routes('http.ts')` file is where you are going to register your Http server routes. Athenna is a framework with a lot of opinions, with predefined diff --git a/docs/getting-started/installation.mdx b/docs/getting-started/installation.mdx index c41eeb00..90f505dc 100644 --- a/docs/getting-started/installation.mdx +++ b/docs/getting-started/installation.mdx @@ -70,5 +70,5 @@ In your project root, run the following command: - The `watch` flag is meant to watch the file system for changes and restart your application automatically when doing some change on it. -- The `serve` command will look up for your `Path.bootstrap('main.js')` +- The `serve` command will look up for your `Path.bootstrap('main.ts')` file to bootstrap your application with predefined configurations. diff --git a/docs/getting-started/node-script-file.mdx b/docs/getting-started/node-script-file.mdx index fbed839a..a3677f98 100644 --- a/docs/getting-started/node-script-file.mdx +++ b/docs/getting-started/node-script-file.mdx @@ -96,7 +96,7 @@ when bootstrapping your application. If you take a look at the content of the node script file, you will see that we are using [sed](https://www.geeksforgeeks.org/sed-command-linux-set-2/) command to replace the `artisan` argument with the path to -`Path.bootstrap('main.js')` file. +`Path.bootstrap('main.ts')` file. This is a tricky implementation that will allow you to call your artisan commands without the need to add the full path diff --git a/docs/rest-api-application/error-handling.mdx b/docs/rest-api-application/error-handling.mdx index 9924b9e3..a1614416 100644 --- a/docs/rest-api-application/error-handling.mdx +++ b/docs/rest-api-application/error-handling.mdx @@ -22,7 +22,7 @@ This documentation will cover about error handling in the **REST API** application, which means that only errors that happens inside routes and bellow that will be handled: -```typescript title="Path.routes('http.js')" +```typescript title="Path.routes('http.ts')" import { Route } from '@athenna/http' // If AppController.show throws, HttpExceptionHandler will handle it 👈 @@ -44,7 +44,7 @@ bootstrap failure has been found in your application. ## Configuration -The `debug` option in your `Path.config('app.js')` configuration +The `debug` option in your `Path.config('app.ts')` configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the `APP_DEBUG` environment @@ -59,13 +59,13 @@ users. Every error will be logged by default using the `console` driver from `@athenna/logger`. By default, Athenna uses the -`exception` channel of your `Path.config('logging.js')` file to log +`exception` channel of your `Path.config('logging.ts')` file to log all exceptions that happens in your application. :::tip You can change the driver and formatter of `exception` -channel inside `Path.config('logging.js')` file. This way you can +channel inside `Path.config('logging.ts')` file. This way you can send all your error logs to another provider and with a different formatter. @@ -121,7 +121,7 @@ export class PaymentRequiredException extends HttpException { You can ignore an exception from being logged if its status code or the code does not match your requirements. To do so you can add the following configurations to the `logger` -property in your `Path.config('http.js')` configuration file: +property in your `Path.config('http.ts')` configuration file: ```typescript export default { @@ -169,7 +169,7 @@ Let's suppose you want to write a custom logic for handling your exceptions. You can do so by creating your own exception handler: -```typescript title="app/http/exceptions/Handler.ts" +```typescript title="app/http/exceptions/Handler.js" import { type ErrorContext, HttpExceptionHandler } from '@athenna/http' export class Handler extends HttpExceptionHandler { @@ -182,7 +182,7 @@ export class Handler extends HttpExceptionHandler { Now you need to register your exception handler when bootstrapping your application: -```typescript filename="Path.bootstrap('main.js')" +```typescript title="Path.bootstrap('main.ts')" await ignite.httpServer({ exceptionHandlerPath: '#app/http/exceptions/Handler', 👈 }) diff --git a/docs/rest-api-application/middlewares.mdx b/docs/rest-api-application/middlewares.mdx index 5cf7bf2a..8d9f62a0 100644 --- a/docs/rest-api-application/middlewares.mdx +++ b/docs/rest-api-application/middlewares.mdx @@ -262,7 +262,7 @@ Route.get('/welcome', () => { :::info The requests log created by Athenna when the `logger` -property is true in your `Path.config('http.js')` file are handled +property is true in your `Path.config('http.ts')` file are handled by a terminator middleware! You can see the code [here](https://github.com/AthennaIO/Http/blob/develop/src/kernels/HttpKernel.ts#L93). ::: diff --git a/docs/rest-api-application/rate-limiting.mdx b/docs/rest-api-application/rate-limiting.mdx index fc580f5b..033fd576 100644 --- a/docs/rest-api-application/rate-limiting.mdx +++ b/docs/rest-api-application/rate-limiting.mdx @@ -21,7 +21,7 @@ a user can request your application in a given time-frame. Athenna uses the [`@fastify/rate-limit`](https://github.com/fastify/fastify-rate-limit) plugin inside `HttpKernel`. All the configurations that -`@fastify/rate-limit` supports can be set inside `Path.config('http.js')` +`@fastify/rate-limit` supports can be set inside `Path.config('http.ts')` file in the `rateLimit` object: ```typescript @@ -43,7 +43,7 @@ export default { In Athenna you can set specific options of rate limit for specific routes. You can also disable the `global` -option of your `rateLimit` configuration in `Path.config('http.js')` +option of your `rateLimit` configuration in `Path.config('http.ts')` and set different rules in your routes: ```typescript diff --git a/docs/rest-api-application/routing.mdx b/docs/rest-api-application/routing.mdx index 24069fc3..acbe15a4 100644 --- a/docs/rest-api-application/routing.mdx +++ b/docs/rest-api-application/routing.mdx @@ -169,13 +169,13 @@ which a browser should permit loading resources. Athenna uses the [`@fastify/cors`](https://github.com/fastify/fastify-cors) plugin inside `HttpKernel`. All the configurations that -`@fastify/cors` supports can be set inside `Path.config('http.js')` +`@fastify/cors` supports can be set inside `Path.config('http.ts')` file in the `cors` object. Cors plugin is registered in your http application by default, but you can remove it uninstalling `@fastify/cors` from your application, or removing the `cors` object key -from your `Path.config('http.js')` file. +from your `Path.config('http.ts')` file. :::tip @@ -186,10 +186,10 @@ consult the [MDN web documentation on CORS](https://developer.mozilla.org/en-US/ ## Custom route file path -You can change the name and the path of your `Path.route('http.js')` file. +You can change the name and the path of your `Path.route('http.ts')` file. To do that you need to set the new path to `Ignite.httpServer()` method: -```typescript filename="Path.bootstrap('dev.js')" +```typescript title="Path.bootstrap('dev.ts')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url) diff --git a/docs/rest-api-application/swagger.mdx b/docs/rest-api-application/swagger.mdx index 1f583b5c..17fbec6b 100644 --- a/docs/rest-api-application/swagger.mdx +++ b/docs/rest-api-application/swagger.mdx @@ -23,9 +23,9 @@ is the root of all awesomeness in Swagger. Athenna uses the [`@fastify/swagger`](https://github.com/fastify/fastify-swagger) and [`@fastify/swagger-ui`](https://github.com/fastify/fastify-swagger-ui) plugins inside `HttpKernel`. All the configurations that `@fastify/swagger` -supports can be set inside `Path.config('http.js')` file in the `swagger.configurations` +supports can be set inside `Path.config('http.ts')` file in the `swagger.configurations` object. And all the configurations that `@fastify/swagger-ui` -supports can be set inside `Path.config('http.js')` file in the `swagger.ui` object: +supports can be set inside `Path.config('http.ts')` file in the `swagger.ui` object: ```typescript export default { diff --git a/docs/rest-api-application/tracing-requests.mdx b/docs/rest-api-application/tracing-requests.mdx index 251ebed2..bdda553a 100644 --- a/docs/rest-api-application/tracing-requests.mdx +++ b/docs/rest-api-application/tracing-requests.mdx @@ -24,7 +24,7 @@ identify bottlenecks and focus on improving performance. Athenna uses the [`cls-rtracer`](https://github.com/puzpuzpuz/cls-rtracer) plugin inside `HttpKernel`. All the configurations that `cls-rtracer` supports can be set inside -`Path.config('http.js')` file in the `rTracer` object: +`Path.config('http.ts')` file in the `rTracer` object: ```typescript export default { @@ -75,7 +75,7 @@ npm remove cls-rtracer You can also disable the tracer by setting `http.trace` to `false`: -```typescript filename="Path.config('http.js')" +```typescript title="Path.config('http.ts')" export default { trace: false, } @@ -84,7 +84,7 @@ export default { Or by setting the `tracer` option as `false` when booting the server in `Ignite.httpServer()` method: -```typescript filename="Path.bootstrap('main.js')" +```typescript title="Path.bootstrap('main.ts')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url) diff --git a/docs/the-basics/logging.mdx b/docs/the-basics/logging.mdx index 0c778fc1..2b633d1a 100644 --- a/docs/the-basics/logging.mdx +++ b/docs/the-basics/logging.mdx @@ -27,7 +27,7 @@ the http requests that your application receives. ## Configuration All the configuration options for your application's logging -behavior are housed in the `Path.config('logging.js')` configuration +behavior are housed in the `Path.config('logging.ts')` configuration file. This file allows you to configure your application's log channels, so be sure to review each of the available channels and their options. We'll review a few common options @@ -39,7 +39,7 @@ Each log channel is powered by a "driver". The driver determines how and where the log message is actually transported. The following log channel drivers are available in every Athenna application. An entry for most of these drivers is already -present in your application's `Path.config('logging.js')` configuration +present in your application's `Path.config('logging.ts')` configuration file, so be sure to review this file to become familiar with its contents: @@ -57,7 +57,7 @@ its contents: Almost all channels doesn't need any additional configuration to work. But some of than need a couple of changes in -`Path.config('logging.js')` file to be able to use. They are `slack`, +`Path.config('logging.ts')` file to be able to use. They are `slack`, `discord` and `telegram`. #### Configuring the Slack channel @@ -157,7 +157,7 @@ import { DriverFactory } from '@athenna/logger' DriverFactory.createDriver('consoleLog', ConsoleLogDriver) ``` -Finally, we can start using our new driver in channels of `Path.config('logging.js')`: +Finally, we can start using our new driver in channels of `Path.config('logging.ts')`: ```typescript channels: { @@ -193,7 +193,7 @@ Log.fatal(message) You may call any of these methods to log a message for the corresponding level. By default, the message will be written to the default log channel as configured by your -`Path.config('logging.js')` configuration file: +`Path.config('logging.ts')` configuration file: ```typescript import { WelcomeService } from '#app/services/WelcomeService' @@ -233,7 +233,7 @@ example configuration that you might see in a production application: Take note of the `level` configuration option present in -`slack` channel of your `Path.config('logging.js')` file: +`slack` channel of your `Path.config('logging.ts')` file: ```typescript channels: { @@ -321,7 +321,7 @@ Log.info(`${chalk.yellow.bold('Hello')} ${chalk.green.italic('World')}!`) It is also possible to set runtime configurations when using the `Log` facade. This way you will never be total -dependent from `Path.config('logging.js')` configuration file. To +dependent from `Path.config('logging.ts')` configuration file. To accomplish this, you may pass a configuration object to the `config` method of Log facade and then call the `channel` method again to set up the configurations for the specified @@ -343,7 +343,7 @@ Each log channel is powered by a "formatter". The formatter determines how the log message is actually formatted. The following log channel formatters are available in every Athenna application. An entry for most of these formatters is -already present in your application's `Path.config('logging.js')` +already present in your application's `Path.config('logging.ts')` configuration file, so be sure to review this file to become familiar with its contents: @@ -409,7 +409,7 @@ FormatterFactory.createFormatter('consoleLog', ConsoleLogFormatter) ``` Finally, we can start using our new formatter in channels -of `Path.config('logging.js')`: +of `Path.config('logging.ts')`: ```typescript channels: { @@ -432,9 +432,9 @@ the application boot process. The same happens when your application is shuting down. If you wish to run your application in silent mode, you can disable this kind -of logs using the `Ignite.load()` method: +of logs using the `Ignite::load()` static method: -```typescript filename="Path.bootstrap('main.js')" +```typescript title="Path.bootstrap('main.ts')" import { Ignite } from '@athenna/core' const ignite = await new Ignite().load(import.meta.url, { diff --git a/docs/the-basics/views.mdx b/docs/the-basics/views.mdx index 8d31e773..a50df6b9 100644 --- a/docs/the-basics/views.mdx +++ b/docs/the-basics/views.mdx @@ -41,7 +41,7 @@ allow you to easily log values, create "if" statements, iterate over data, and more. Once you have created a view file, eg: `resources/views/welcome.edge`, -you may register your view disk inside `Path.config('view.js')` file: +you may register your view disk inside `Path.config('view.ts')` file: ```typescript import { Path } from '@athenna/common' @@ -184,7 +184,7 @@ time-consuming process, and hence it is recommended to cache the compiled templates in production. You can control the template caching using the `edge.cache` -property inside `Path.config('view.js')` file. Just make sure to set +property inside `Path.config('view.ts')` file. Just make sure to set the value to `true` in the production environment: ```typescript