{
"autoload": {
"App": "./app"
}
}
You are viewing the legacy version of AdonisJS. Visit https://adonisjs.com for newer docs. This version will receive security patches until the end of 2021.
The guide is geared towards giving you an in-depth understanding of the AdonisJs application flow. The flow is divided into three broad categories of HTTP Server, Ace Command and HTTP Request.
The HTTP server involves wiring the pieces of application together and booting the HTTP server. This is a one-time job since the HTTP server is a long running process.
The first step is to load all the providers and set up their aliases. Let’s talk about all the involved steps:
Providers and their aliases are defined inside bootstrap/app.js
file.
The bootstrap/http.js
file will make use of the providers
array and will register them with the IoC container.
Next, we register the autoloading directory defined inside package.json
file. You free to change the directory or the autoloading namespace which is set to App
.
{
"autoload": {
"App": "./app"
}
}
The boot process will then load the following files in defined sequence.
bootstrap/events.js
app/Http/kernel.js
app/Http/routes.js
database/factory.js
Finally, it will start the HTTP server by listening on the host and port defined inside .env
file and emits Http.start
event, which you can listen to hook your custom implementations.
The process of wiring up the ace command is similar to the Http Server but following differences.
All Providers defined inside bootstrap/app.js
file will be loaded. Which means aceProviders
and providers
will be concatenated and sent to the IoC container.
All commands
array will be registered with Ace.
This time Ace.start
event gets emitted instead of Http.start
.
HTTP request is a dynamic flow of processing one or more HTTP requests at a given time.
The incoming request URL is checked against a static file inside the public
directory and if found the static file will be served.
Next, a corresponding route will get searched against the request URL and following steps are performed.
Run all global middleware
Run all route specific middleware
Execute route action which can be a Controller method or a Closure.
If above 2 are false a 404 HttpException
will be thrown.