Skip to content

Commit

Permalink
dirty commit for issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexej Yaroshevich committed Dec 16, 2013
1 parent 800a7bf commit c1d2b06
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 41 deletions.
43 changes: 4 additions & 39 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@

var http = require('http')
, bemRender = require('lib/bem-render-middleware')
var bemRender = require('lib/bem-render-middleware')
, httpProxy = require('http-proxy');

httpProxy.createServer(
bemRender.pages('pages'),
bemRender.bundles('pages'),
function (req, res, next) {
res.setHeader('X-Powered-By', 'bem-proxy');
next();
},
9000, 'localhost'
).listen(8001);

http.createServer(function (req, res) {
require('fs').readFile('bem-examples/www/pages/example/example.bemjson.js', function (err, data) {
if (err) {
res.writeHead(500);
res.end('Something went wrong: ' + e.message);
res.end();
return;
}
res.writeHead(200, { 'Content-Type': 'application/x-bemjson' });
res.write(data);
res.end();
});
}).listen(9000);

/*
http.createServer(function (req, res) {
http.get("http://interactive-answers.yandex.ru/api/2.x/site/d89cda99-274e-47be-abe5-ac0ed339a083/search", function (gres) {
res.writeHead(200, { 'Content-Type': 'application/x-bemjson' });
res.write('request successfully proxied: ' + req.url +'\n');
res.write(JSON.stringify(req.headers, true, 2));
res.write(JSON.stringify(gres.headers, true, 2));
gres.on('data', function (chunk) {
res.write(chunk);
});
gres.on('end', function (chunk) {
res.end();
});
}).on('error', function (e) {
res.writeHead(500);
res.end('Something went wrong: ' + e.message);
});
}).listen(9000);
*/
80, 'localhost'
).listen(process.env.NODE_PORT);
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

var bemRender = require('lib/bem-render-middleware')
, httpProxy = require('http-proxy');

exports.createServer = function (path, port, host) {
port = port || 80;
host = host || 'localhost';
return httpProxy.createServer(
bemRender.bundles(path),
function (req, res, next) {
res.setHeader('X-Powered-By', 'bem-proxy');
next();
},
port, host
);
};
2 changes: 1 addition & 1 deletion lib/bem-render-middleware.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* jshint: node */

exports.pages = function (path) {
exports.bundles = function (path) {
"use strict";

var bemRenderContentType = 'application/x-bemjson';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"url": "https://github.com/zxqfox/bem-proxy/issues"
},
"dependencies": {
"bem": "~0.6.16",
"bem": "~1.0.0",
"http-proxy": "~0.10.3"
},
"devDependencies": {
Expand Down

0 comments on commit c1d2b06

Please sign in to comment.