rocore
v2.1.1
Published
Generator async module
Downloads
6
Readme
rocore
code async with ECMAScript 6 generator.
Install
$ npm install rocore
Useage
// server.js
import * as Rocore from 'rocore';
import Http from 'http';
import Qs from 'querystring';
import Fs from 'fs';
var server = Http.createServer();
var app = Rocore.createApplication();
app
.on('found', (route, req, res) => {
req.body = {}; // parsing body
app.exec(route, req, res);
})
.on('notfound', (req, res) => {
res.writeHead(404);
res.end();
})
.get('/demo/:username?mark=1', who, send);
server
.on('request', (req, res) => {
app.match(req, res);
})
.listen(8000);
function* who(ynext, next, req, res) {
console.log(req.protocol);
console.log(req.auth);
console.log(req.hostname);
console.log(req.port);
console.log(req.pathname);
console.log(req.params.username);
console.log(req.query.mark);
console.log(req.hash);
yield* next;
}
function* send(ynext, next, req, res) {
var [err, data] = yield Fs.readFile('/home/username/test.js', 'utf8', ynext);
res.write(data);
res.end();
}
[Need https://github.com/babel/babel] (ECMAScript 6)
$ npm install -g babel $ babel-node server.js