data-sectionで1スクリプトhttpサーバ
httpサーバのレスポンスをdata-sectionモジュール使って返すようにしただけのコードです……
var http = require('http'), dataSection = require('data-section'), server = http.createServer(); dataSection.get('index.html', function (err, data) { if (err) throw err; server.on('request', function (req, res) { res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }); res.end(data); }); server.listen(3000); }); /*__DATA__ @@ index.html <!DOCTYPE html> <meta charset="utf-8"> <title>インターネット</title> <style>p {text-align: center}</style> <p>インターネット</p> __DATA__*/
Rubyとかで__END__とかあまり書いたことなくて、何がうれしいんだろうと思ってたけど、ヒアドキュメント的に書けるし、1ファイルなので管理が楽なところがすごく良いことだなあと思いました。まる。