hc

http-connect

a module that make http instance compatible with connect middleware

Showing:

Popularity

Downloads/wk

11

GitHub Stars

1

Maintenance

Last Commit

6yrs ago

Contributors

1

Package

Dependencies

2

Size (min+gzip)

11.7KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

HTTP-Connect

HTTP-Connect is a module that make http instance compatible with connect middleware. [http://senchalabs.github.com/connect]

var PORT = 3000;
var http = require('http');

var url = require('url');

var connect = require('http-connect');

var server = http.createServer(function (request, response) {
  var app = connect({
    req: request,
    res: response,
    pathname: url.parse(request.url).pathname
  });

  var cookieParser = require('cookie-parser');

  app.use(cookieParser());

  app.use(function(req, res, next){
    res.write(JSON.stringify(req.cookies));
    res.end();
  });
});

server.listen(PORT);

console.log("Server runing at port: " + PORT + ".");

Install HTTP-Connect

$ npm install http-connect

Use with think.js

HTTP-Connect can be used in think.js controllers.

var connect = require('http-connect');

module.exports = Controller("Home/BaseController", function(){
  "use strict";
  return {
    init: function(http){
      this.super("init", http);
      //其他的通用逻辑
    },
    indexAction: function(){
      var self = this;
      var app = connect(this.http);

      app.use(function(req, res, next){
        //do sth.
      });
    }
  };
});

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100