koa-server
A HTTP Server for NodeJS and Koa
Install
npm install koa-server --save
Usage
Create a http server
var KoaServer = var server = server server
You can run multiple servers
var server1 = var server2 = server1server2 server1server2
Use some middlewares
server { ifthisdatatopic next }{ console next}
Or, you can use some middlewares for all routers
var KoaServer = var sleep = var server = use: log abc { console next}{ thisabc = 'abc' next} server
Support the routers: all, get, post, put, delete
The this.param is the value of url's path
The this.data is the data from request ( GET's query, others' body )
{ // The param and data will convert some value'type automatically // For example: // '18' -> 18 // '4.5' -> 4.5 // 'true' -> true // 'false' -> false // 'null' -> null // '' -> null thisbody = param: thisparam data: thisdata } serverall'/books/:name/:page' responseserverserverserverserver
To render a page ( template's extname should be the .html )
var server = // The directory to store html files // default: 'view' view: '/pages' // The template engine, need to install package // default: 'hogan' engine: 'mustache' server
User base path and static resources
var server = base: 'child-site' static: 'css''js''image' // Real path: child-site/view/index.htmlthisbody = this
<!-- Real path: child-site/css/index.css --> <!-- Real path: child-site/js/index.js --> <!-- Real path: child-site/image/logo.png -->
Support file upload
// Must ensure the save directory ( the 'tmp' in example ) has existed// Must yield to nextserver
You can check file size or rename file
server
To handle cookie
// Getserver// Setserver
You can set more options
server
To handle session
// Get and set sessionserver // Clear sessionserver
A syntactic sugar for file's IO
server
Build-in the markdown function ( GitHub Flavored )
server
To operate MongoDB
var server = mongo: defaultDB: 'test' server
You can set more options
var server = // These values in the example is default mongo: host: 'localhost' port: 27017 user: null pass: null min: 1 max: 100 timeout: 30000 defaultDB: 'test' log: false
Here are some examples, please see more in 'demo/mongo/index.js'
server server server server server
Of course, included the functions of koa-app
server