Version 2 of Foal has been released in December 2020 🎉. This series of four articles presents the major new features.
Let’s get started!
New CLI commands#[1]
In version 1, there were many commands to use, and this, in a specific order. Running and generating migrations from model changes required four commands and building the whole application needed three.
In version 2, the number of CLI commands has been reduced and they have been simplified so that one action matches one command.
Generating migrations#[2]
This command generates migrations by comparing the current database schema and the latest changes in your models.
- Version 2
- Version 1
Running migrations#[3]
This command builds and runs all migrations.
- Version 2
- Version 1
Build and run scripts in watch mode (development)#[4]
If you want to re-build your scripts each time a file is change, you can execute npm run develop
in a separate terminal.
- Version 2
- Version 1
Revert one migration#[5]
This command reverts the last executed migration.
- Version 2
- Version 1
Build migrations, scripts and the app#[6]
This command builds the application, the scripts and the migrations. Unit and e2e tests are not included.
- Version 2
- Version 1
Service and Application Initialization#[7]
In version 1, it was possible to add an init
method to the AppController
class and boot
methods in the services to initialize the application. These features needed special options in order to be activated.
Starting from version 2, they are enabled by default.
The AppController
interface#[8]
This optional interface allows you to check that the subControllers
property has the correct type as well as the init
and handleError
methods.
Custom Error-Handling & Hook Post Functions#[9]
In version 1, when an error was thrown or rejected in a hook or a controller method, the remaining hook post functions were not executed.
Starting from version 2, the error is directly converted to an HttpResponseInternalServerError
and passed to the next post hook functions.
This can be useful in case we want to use exceptions as HTTP responses without breaking the hook post functions.
Example
Accessing File Metadata during Uploads#[10]
When using the @ValidateMultipartFormDataBody
hook to handle file upload, it is now possible to access the file metadata.
Example
Property name | Type | Description |
---|---|---|
encoding |
string |
Encoding type of the file |
filename |
string|undefined |
Name of the file on the user’s computer |
mimeType |
string |
Mime type of the file |
path |
string |
Path where the file has been saved. If the saveTo option was not provided, the value is an empty string. |
buffer |
Buffer |
Buffer containing the entire file. If the saveTo option was provided, the value is an empty buffer. |
References
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
- ^ Direct link to heading (foalts.org)
Source: Echo Js