opinion
this is my opinion on koa and stuff
Last updated 6 years ago by refack .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install opinion 
SYNC missed versions from official npm registry.

Build Status

NPM

koa opinions

Originally forked from koajs/common

Installation

$ npm install opinion

default configuration

a builtin routing mechanism

An extensive default middleware stack

DEFAULT_MIDDLEWARE_STACK = {
    NoKeepAlive: common.NoKeepAlive,
    responseTime: common.responseTime,
    logger: common.logger,
    compress: common.compress,
    conditionalGet: common.conditionalGet,
    etag: common.etag,
    statics: common.statics,
    session: common.session,
    csrf: common.csrf,
    router: common.router
};

The request ctx has been extended with a send method to send files, and a render method to render views using any consolidate compatible render engine, or plain html files.

And as a extra bonus, socket.io is builtin and can be enabled by configuration flag.

Usage

"use strict";
var opinion = require('opinion');


var app = opinion({
    middlewareOrder: opinion.DEFAULT_MIDDLEWARE_STACK, // this can be manipulated
    // here are some configurations, both general, and middleware specific (by name)
    keys: ['78fd9fe83f2af46f2a8b567154db8d2a'],
    statics: 'assets',
    render: ['views', 'dust'],
    socketio: { clientPath: '/js/socket.io.js' }
});


// simple route
app.get('/',
    function* () {
        yield this.render('hello-world');
    }
);


// a CORS enabled proxy to `gist.github.com`
app.get('/snippet/cors/:user/:id', function* () {
    this.set('Access-Control-Allow-Origin', '*');
    this.set('Access-Control-Allow-Methods', 'GET');
    this.set('Access-Control-Allow-Headers', 'Content-Type');
    this.type = 'application/javascript';
    this.body = require('request')('https://gist.github.com/' + this.params.user + '/' + this.params.id + '/raw');
});


app.listen(prosess.env.PORT || 8080, function () {
    console.log("Server listening on %s", this._connectionKey);
});


// websocket push example
setInterval(function () {
    app.webSockets.emit('gaga', JSON.stringify(process.memoryUsage()))
}, 3000);

License

MIT

Current Tags

  • 1.0.36                                ...           latest (6 years ago)

37 Versions

  • 1.0.36                                ...           6 years ago
  • 1.0.35                                ...           6 years ago
  • 1.0.34                                ...           6 years ago
  • 1.0.33                                ...           6 years ago
  • 1.0.32                                ...           6 years ago
  • 1.0.31                                ...           6 years ago
  • 1.0.30                                ...           6 years ago
  • 1.0.29                                ...           6 years ago
  • 1.0.28                                ...           6 years ago
  • 1.0.27                                ...           6 years ago
  • 1.0.26                                ...           6 years ago
  • 1.0.25                                ...           6 years ago
  • 1.0.24                                ...           6 years ago
  • 1.0.23                                ...           6 years ago
  • 1.0.22                                ...           6 years ago
  • 1.0.21                                ...           6 years ago
  • 1.0.20                                ...           6 years ago
  • 1.0.19                                ...           6 years ago
  • 1.0.18                                ...           6 years ago
  • 1.0.17                                ...           6 years ago
  • 1.0.16                                ...           6 years ago
  • 1.0.15                                ...           6 years ago
  • 1.0.14                                ...           6 years ago
  • 1.0.13                                ...           6 years ago
  • 1.0.12                                ...           6 years ago
  • 1.0.11                                ...           6 years ago
  • 1.0.10                                ...           6 years ago
  • 1.0.9                                ...           6 years ago
  • 1.0.8                                ...           6 years ago
  • 1.0.7                                ...           6 years ago
  • 1.0.6                                ...           6 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           7 years ago

Copyright 2014 - 2017 © taobao.org |