1.0.36 • Published 10 years ago

opinion v1.0.36

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

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

1.0.36

10 years ago

1.0.35

10 years ago

1.0.34

10 years ago

1.0.33

10 years ago

1.0.32

10 years ago

1.0.31

10 years ago

1.0.30

10 years ago

1.0.29

10 years ago

1.0.28

10 years ago

1.0.27

10 years ago

1.0.26

10 years ago

1.0.25

10 years ago

1.0.24

10 years ago

1.0.23

10 years ago

1.0.22

10 years ago

1.0.21

10 years ago

1.0.20

10 years ago

1.0.19

10 years ago

1.0.18

10 years ago

1.0.17

10 years ago

1.0.16

10 years ago

1.0.15

10 years ago

1.0.14

10 years ago

1.0.13

10 years ago

1.0.12

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago