Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect use #22

Closed
7 tasks done
azu opened this issue Aug 29, 2015 · 15 comments
Closed
7 tasks done

Connect use #22

azu opened this issue Aug 29, 2015 · 15 comments
Labels
help wanted Extra attention is needed Status: Proposal Request for comments

Comments

@azu
Copy link
Owner

azu commented Aug 29, 2015

Connectのアーキテクチャ

URL: https://github.com/senchalabs/connect

どう書ける?

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

var app = connect()

// gzip/deflate outgoing responses
var compression = require('compression')
app.use(compression())

// store session state in browser cookie
var cookieSession = require('cookie-session')
app.use(cookieSession({
    keys: ['secret1', 'secret2']
}))

// parse urlencoded request bodies into req.body
var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded())

// respond to all requests
app.use(function(req, res){
  res.end('Hello from Connect!\n');
})

//create node.js http server and listen on port
http.createServer(app).listen(3000)

どういう仕組み? #57

どういう事に向いてる?

  • TBD

この仕組みを使ってるもの


チェックリスト

  • どう書ける?
  • どういう仕組み?
  • どういう用途に向いている?
  • どういう用途に向いていない?
  • この仕組みを使ってるもの
  • 実装してみよう
  • エコシステム
@azu
Copy link
Owner Author

azu commented Aug 29, 2015

Node.jsのモジュールで.use(plugin)的なものが結構多い気がするけど、
これは何が起源なんだろ? connectが最初なのかな?

@azu azu added Status: Proposal Request for comments help wanted Extra attention is needed labels Aug 29, 2015
@ledsun
Copy link

ledsun commented Aug 30, 2015

connectのuseはRack DSL起源ではないでしょうか?
実践Node.js プログラミングのP149に

Connect ミドルウェアのコンセプトは、もともと Ruby の Rack フレームワークの影響を受けている。
だから Rack と非常によく似たモジュールインタフェースを提供するが、Node はストリーミング方式なので
API は共通ではない。

という記述がありました。

Ruby - Rack解説 - Rackの構造とRack DSL - Qiitaに、useメソッドを使うと

run Rack::ETag.new(
  Rack::Deflater.new(
    Rack::Directory.new 'public'
  )
)

を次のように書ける

use Rack::ETag
use Rack::Deflater
run Rack::Directory.new 'public'

という例がありました。とてもconnectぽいと思います。

@azu
Copy link
Owner Author

azu commented Aug 30, 2015

@ledsun ありがとうございます。なるほど。
たしかにconnectのはrackに影響受けてそうですね。

package.jsonのkeywordsにもrackがあったりしました

@azu
Copy link
Owner Author

azu commented Sep 7, 2015

コールドリーディング v2

@azu
Copy link
Owner Author

azu commented Sep 8, 2015

@azu
Copy link
Owner Author

azu commented Sep 12, 2015

connectはmiddleware間の依存関係とか定義ないので、色々自分でガンバってやる必要があって、細かいのは実装でやってね的な感じっぽいな

@azu
Copy link
Owner Author

azu commented Sep 12, 2015

Node.js - 逆引きメモ:expressの使い方 - Qiitaはmiddlewareの考え方が簡単にまとまってる。

@azu
Copy link
Owner Author

azu commented Sep 12, 2015

@azu
Copy link
Owner Author

azu commented Sep 12, 2015

ミドルウェアとは何かを一言で言うと,「別なアプリケーションをラップして,リクエストやレスポンスを加工したり,処理を切り換えたりするRackアプリケーション」です
-- http://gihyo.jp/dev/serial/01/ruby/0025

@azu
Copy link
Owner Author

azu commented Sep 12, 2015

このミドルウェアの連鎖をミドルウェアスタックといいます。
-- 第3回 WSGIミドルウェアの作成:WSGIとPythonでスマートなWebアプリケーション開発を|gihyo.jp … 技術評論社

Rack middlewareの仕組みの元ネタはPythonのWSGI middlewareという感じなのかな

@azu
Copy link
Owner Author

azu commented Sep 12, 2015

Connectに統一しよう #48

@azu azu changed the title connect use Connect use Sep 13, 2015
@azu azu mentioned this issue Sep 13, 2015
4 tasks
@azu
Copy link
Owner Author

azu commented Sep 13, 2015

この仕組みエラーハンドリングがイマイチピンとこないという大変そう

やっぱり実際大変なのかな

@azu
Copy link
Owner Author

azu commented Sep 15, 2015

middlewareスタックなやつ、直接オブジェクトを変更しないで、抽象オブジェクトを入れて編集させれば矛盾ある変更とかの検知ができるようになる気がする

@azu
Copy link
Owner Author

azu commented Sep 19, 2015

ひとまず書けたのでCloseします

微妙に曖昧なところもあるので Pull Request歓迎です

@azu azu closed this as completed Sep 19, 2015
@azu
Copy link
Owner Author

azu commented Sep 26, 2015

middlewareの仕組み

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

2 participants