Created
April 22, 2013 14:06
-
-
Save jalalhejazi/5435385 to your computer and use it in GitHub Desktop.
nodejs: Node create server and send data.json filecontent to client of CORS !
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
/* | |
Response header info: | |
Access-Control-Allow-Origin:* | |
Content-Type:text/json | |
X-Powered-By:nodejs | |
*/ | |
var http = require('http'); | |
var fs = require('fs'); | |
var port = "1111" ; | |
http.createServer(function(request, response) { | |
response.writeHead(200, { | |
'Content-Type': 'text/json', | |
'Access-Control-Allow-Origin': '*', | |
'X-Powered-By':'nodejs' | |
}); | |
fs.readFile('data.json', function(err, content){ | |
response.write(content); | |
response.end(); | |
}); | |
}).listen(port); | |
console.log("Listening on port " + port ); |
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
{ | |
"author" : "Jalal.Hejazi" , | |
"info" : "Response header info" , | |
"Content-Type": "text/json" , | |
"X-Powered-By" : "nodejs" , | |
"Access-Control-Allow-Origin" : "*" , | |
"next" : "REST The WEB" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment