Core Trailpack. This pack is required by all Trails applications, and is reponsible for validating the API definition (the stuff in api/), merging environment-specific configuration, binding context on Controllers, Services, and Policies, and other important and fundamental things.
In particular, this trailpack includes and configures two very important things:
- Logging
- Internationalization (i18n)
$ npm install --save trailpack-core
The core trailpack should always be loaded in your trailpack config.
// config/trailpack.js
module.exports = {
// ...
packs: [
require('trailpack-core')
]
}
This trailpack exposes the configured logger (in config.log
) on the main app
object. See archetype/config/log.js
for an example configuration.
// api/controllers/ExampleController.js
module.exports = class ExampleController extends Controller {
/**
* Logs the querystring
*/
exampleHandler (req, res) {
this.log.debug(req.query)
}
}
This trailpack also exposes the i18next translator function on the main app
object as app.__
and app.t
. See archetype/config/i18n.js
for an example configuration.
// config/locales/en.json
{
"helloworld": "Hello World"
}
// api/controllers/ExampleController.js
module.exports = class ExampleController extends Controller {
/**
* Returns the string "Hello World" if locale is set to "en"
*/
exampleHandler (req, res) {
this.app.t('helloworld')
}
}
We love contributions! Please check out our Contributor's Guide for more information on how our projects are organized and how to get started.