GithubHelp home page GithubHelp logo

trailpack-core's Introduction

trailpack-core

Gitter NPM version Build status Dependency Status Code Climate Follow @trailsjs on Twitter

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)

Install

$ npm install --save trailpack-core

Usage

Configuration

The core trailpack should always be loaded in your trailpack config.

// config/main.js
module.exports = {
  // ...
  packs: [
    require('trailpack-core')
  ]
}

Logging

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)
  }
}

Internationalization

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')
  }
}

Contributing

We love contributions! Please check out our Contributor's Guide for more information on how our projects are organized and how to get started.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.