rocore

2.1.1 • Public • Published

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

$ npm install -g babel $ babel-node server.js

→ API document

Readme

Keywords

Package Sidebar

Install

npm i rocore

Weekly Downloads

28

Version

2.1.1

License

MIT

Last publish

Collaborators

  • tulayang