trailpack-koa
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.jsmoduleexports = packs: // ... other trailpacks
Web
const env = // config/web.jsmoduleexports = /** * Koa package * @type * @required */ koa: /** * Better customize Koa * @type * @required */ {} /** * SSL options * Cert and key or pfx to create HTTPS server * @type */ // ssl: { // /** // * Private Key .key // * @type {string} // */ // key: '...', // /** // * Certificate PEM .pem // * @type {string} // */ // cert: '...' // }, /** * SPDY options * @type */ // 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 /** * The host to bind the web server to * @type string * @default localhost */ host: env /** * Feature for koa.context.onerror handler * @type * @default true */ onError: true /** * Feature koa-compress * https://www.npmjs.com/package/koa-compress * @type * @default true */ compress: true /** * Feature koa-cors * https://www.npmjs.com/package/koa-cors * @type * @default true */ cors: true /** * Feature koa-session * https://www.npmjs.com/package/koa-cors * @type */ session: true /** * Feature koa-bodyparser * https://www.npmjs.com/package/koa-bodyparser * @type */ bodyparser: true /** * Middlewares * @type */ // middlewares: {}, /** * Middlewares Order * @type */ // middlewaresOrder: [ // 'compress', // 'cors', // 'session', // 'bodyparser', // 'router', // '404' // ]
Socket
// config/socket.jsmoduleexports = /** * Socket.io package * @type * @required */ scoketIo: /** * Better customize Scoket.io * @type * @required */ {} /** * Socket.io parameters * https://www.npmjs.com/package/socket.io * @type */ // params: {}, /** * Socket.io sticky session parameters * https://www.npmjs.com/package/socketio-sticky-session * @type * @default false */ cluster: false
Controllers / Routes
Doc for Controllers and Routes can be found here!
Policies
Doc for Policies can be found here!
Credits
- Written based on trailpack-express and trailpack-hapi
- Koa
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.