Last active
August 29, 2015 14:05
-
-
Save lzhoucs/d3c7bed0d199fb0e2abf to your computer and use it in GitHub Desktop.
Simple tools and programs written in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this program is used to issue multiple http POST requests concurrently, in order to test/examine server side concurrenct issue. | |
var http = require('http'); | |
var post_options = { | |
host: 'localhost', | |
port: '8080', | |
path: '/merchtools/editor/formatter/us', | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded' | |
// ,'Content-Length': post_data.length | |
} | |
}; | |
var data1 = 'data=<Property name="boostNavStateConfig"> <aaa:Item class="com.nike.onestore.assembler.cartridge.model.NavigationStateConfig" xmlns:aaa="http://endeca.com/schema/xavia/2010"> <aaa:Property name="propertyType"> <aab:String xmlns:aab="http://endeca.com/schema/content-template/2008">dynamic</aab:String> </aaa:Property> <aaa:Property name="rollup"> <aab:Boolean xmlns:aab="http://endeca.com/schema/content-template/2008">true</aab:Boolean> </aaa:Property> <aaa:Property name="boostStrata"> <aaa:List> <aaa:Item class="com.endeca.infront.navigation.model.CollectionFilter"> <aaa:Property name="innerFilter"> <aaa:Item class="com.endeca.infront.navigation.model.AndFilter"> <aaa:Property name="operands"> <aaa:List> <aaa:Item class="com.endeca.infront.navigation.model.DimensionFilter"> <aaa:Property name="dvalId">10001</aaa:Property> <aaa:Property name="dimensionName">Gender</aaa:Property> </aaa:Item> </aaa:List> </aaa:Property> </aaa:Item> </aaa:Property> </aaa:Item> </aaa:List> </aaa:Property> </aaa:Item> </Property>'; | |
var data2 = 'data=<Property name="buryNavStateConfig"> <aaa:Item class="com.nike.onestore.assembler.cartridge.model.NavigationStateConfig" xmlns:aaa="http://endeca.com/schema/xavia/2010"> <aaa:Property name="propertyType"> <aab:String xmlns:aab="http://endeca.com/schema/content-template/2008">dynamic</aab:String> </aaa:Property> <aaa:Property name="rollup"> <aab:Boolean xmlns:aab="http://endeca.com/schema/content-template/2008">true</aab:Boolean> </aaa:Property> <aaa:Property name="boostStrata"> <aaa:List> <aaa:Item class="com.endeca.infront.navigation.model.CollectionFilter"> <aaa:Property name="innerFilter"> <aaa:Item class="com.endeca.infront.navigation.model.AndFilter"> <aaa:Property name="operands"> <aaa:List> <aaa:Item class="com.endeca.infront.navigation.model.DimensionFilter"> <aaa:Property name="dvalId">10005</aaa:Property> <aaa:Property name="dimensionName">Gender</aaa:Property> </aaa:Item> </aaa:List> </aaa:Property> </aaa:Item> </aaa:Property> </aaa:Item> </aaa:List> </aaa:Property> </aaa:Item> </Property>'; | |
var dataArr = [data1, data2]; | |
dataArr.forEach( function(data) { | |
var post_req = http.request(post_options, function(resp) { | |
resp.setEncoding('utf8'); | |
resp.on('data', function (chunk) { | |
console.log('Response: ' + chunk); | |
}); | |
}); | |
post_req.write(data); | |
post_req.end(); | |
} ) | |
console.log('Done.'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this program serves as a fake http authentication server which only return 'true' when ws.user=admin | |
var http = require('http'); | |
var url = require('url'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
var queryStrs = url.parse(req.url, true).query; | |
var user = queryStrs["ws.user"]; | |
if("admin" === user) { | |
res.end('true\n'); | |
} else { | |
res.end('false\n'); | |
} | |
}).listen(5006, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:5006/'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var urlParser = require('url'); | |
var endPointPing = "/onestore/dynamic-config/load-seo-config"; | |
var endPointApply = "/onestore/dynamic-config/apply-seo-config"; | |
http.createServer(function (req, res) { | |
var subPath = req.url; | |
var message; | |
var sessionToken = urlParser.parse(subPath).search || ""; | |
var reqUrl = "http://127.0.0.1:8080/merchtools/get-data.xml" + sessionToken; | |
if(subPath.indexOf(endPointPing) != -1) { | |
message = "Getting back ping request 200"; | |
console.log(message); | |
console.log("ReqUrl : " + reqUrl); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end(message); | |
http.get(reqUrl, function(res) { | |
console.log("Got response: " + res.statusCode); | |
}).on('error', function(e) { | |
console.log("Got error: " + e.message); | |
}); | |
} else if(subPath.indexOf(endPointApply) != -1) { | |
message = "Getting back apply request 200"; | |
console.log(message); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end(message); | |
} else { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end("Not valid path. But 200 anyway."); | |
} | |
}).listen(7144, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:7144/'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment