refactor 3-more into separate books
This commit is contained in:
parent
bd1d5e4305
commit
87639b2740
423 changed files with 9 additions and 9 deletions
38
4-ajax/10-ajax-jsonp/jsonp.view/server.js
Normal file
38
4-ajax/10-ajax-jsonp/jsonp.view/server.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
var http = require('http');
|
||||
var url = require('url');
|
||||
var static = require('node-static');
|
||||
var file = new static.Server('.', { cache: 0 });
|
||||
|
||||
|
||||
function accept(req, res) {
|
||||
|
||||
var urlParsed = url.parse(req.url, true);
|
||||
|
||||
if (urlParsed.pathname == '/user') {
|
||||
var id = urlParsed.query.id;
|
||||
var callback = urlParsed.query.callback;
|
||||
|
||||
res.setHeader('Content-Type', 'application/javascript; charset=utf-8');
|
||||
|
||||
var user = {
|
||||
name: "Вася",
|
||||
id: id
|
||||
};
|
||||
|
||||
res.end(callback + '(' + JSON.stringify(user) + ')');
|
||||
|
||||
} else {
|
||||
file.serve(req, res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ------ запустить сервер -------
|
||||
|
||||
if (!module.parent) {
|
||||
http.createServer(accept).listen(8080);
|
||||
} else {
|
||||
exports.accept = accept;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue