Neanderthals Programming Machines
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

trailpack-koa

3.0.2 • Public • Published

trailpack-koa

NPM version Build status Dependency Status Code Climate Donate

Use Koa as your Trails server

support web socket, http, https and spdy

Dependencies

  • TrailsJS@^3
  • Koa@^2

Compatibilities

  • Footprint

Install

NPM

$ npm install --save trailpack-koa

Yarn

$ yarn add trailpack-koa

Configure

Main

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

Web

const env = require('env-var')
 
// config/web.js
module.exports = {
  /**
   * Koa package
   * @type {function} 
   * @required
   */
  koa: require('koa'),
  /**
   * Better customize Koa
   * @type {function} 
   * @required
   */
  init: (trailsApp, koaApp) => {},
  /**
   * SSL options
   * Cert and key or pfx to create HTTPS server
   * @type {object} 
   */
  // ssl: {
  //   /**
  //    * Private Key .key
  //    * @type {string}
  //    */
  //   key: '...',
  //   /**
  //    * Certificate PEM .pem
  //    * @type {string}
  //    */
  //   cert: '...'
  // },
  /**
   * SPDY options
   * @type {object} 
   */
  // spdy: {
  //   /**
  //    * list of NPN/ALPN protocols to use
  //    * @type {array}
  //    * @default ['h2','spdy/3.1','spdy/3','spdy/2','http/1.1','http/1.0']
  //    */
  //   protocols: ['h2','spdy/3.1','spdy/3','spdy/2','http/1.1','http/1.0'],
  //   /**
  //    * If defined, server will ignore NPN and ALPN data and choose whether to use spdy or plain http by looking at first data packet.
  //    * @type {boolean}
  //    */
  //   plain: false,
  //   /**
  //    * Parse first incoming X_FORWARDED_FOR frame and put it to the
  //    * headers of every request.
  //    * NOTE: Use with care! This should not be used without some proxy that
  //    * will *always* send X_FORWARDED_FOR
  //    */
  //   'x-forwarded-for': false,
  //   /**
  //    * SPDY Connection options
  //    * @type {object}
  //    */
  //   connection: {
  //     /**
  //      * Server's window size
  //      * @type {number}
  //      */
  //     windowSize: 1024 * 1024,
  //     /**
  //      * If true - server will send 3.1 frames on 3.0 *plain* spdy
  //      * @type {boolean}
  //      */
  //     autoSpdy31: false
  //   }
  // },
  /**
   * The port to bind the web server to
   * @type number
   * @default 3000
   */
  port: env.get('PORT', 3000).asIntPositive(),
  /**
   * The host to bind the web server to
   * @type string
   * @default localhost
   */
  host: env.get('HOST', 'localhost').asString(),
 
  /**
   * Feature for koa.context.onerror handler
   * @type {boolean|function} 
   * @default true
   */
  onError: true,
  /**
   * Feature koa-compress
   * https://www.npmjs.com/package/koa-compress
   * @type {boolean|object} 
   * @default true
   */
  compress: true,
  /**
   * Feature koa-cors
   * https://www.npmjs.com/package/koa-cors
   * @type {boolean|object} 
   * @default true
   */
  cors: true,
  /**
   * Feature koa-session
   * https://www.npmjs.com/package/koa-cors
   * @type {boolean|object} 
   */
  session: true,
  /**
   * Feature koa-bodyparser
   * https://www.npmjs.com/package/koa-bodyparser
   * @type {object} 
   */
  bodyparser: true,
 
  /**
   * Middlewares
   * @type {object} 
   */
  // middlewares: {},
  /**
   * Middlewares Order
   * @type {object} 
   */
  // middlewaresOrder: [
  //   'compress',
  //   'cors',
  //   'session',
  //   'bodyparser',
  //   'router',
  //   '404'
  // ]
}

Socket

// config/socket.js
module.exports = {
  /**
  * Socket.io package
  * @type {function} 
  * @required
  */
  scoketIo: require('socket.io'),
  /**
   * Better customize Scoket.io
   * @type {function} 
   * @required
   */
  init: (trailsApp, koaApp) => {},
  /**
   * Socket.io parameters
   * https://www.npmjs.com/package/socket.io
   * @type {object} 
   */
  // params: {},
  /**
   * Socket.io sticky session parameters
   * https://www.npmjs.com/package/socketio-sticky-session
   * @type {boolean|object} 
   * @default false
   */
  cluster: false
}

Controllers / Routes

Doc for Controllers and Routes can be found here!

Policies

Doc for Policies can be found here!

Credits

Please Contribute!

I'm happy to receive contributions of any kind!

Did you like my work?

Help me out with a little donation, press on the button below. Donate

Install

npm i trailpack-koa

DownloadsWeekly Downloads

0

Version

3.0.2

License

MIT

Unpacked Size

224 kB

Total Files

56

Homepage

trailsjs.io

Last publish

Collaborators

  • avatar