Skip to content

Instantly share code, notes, and snippets.

@worldofchris
Created January 29, 2013 13:39
Show Gist options
  • Save worldofchris/4664303 to your computer and use it in GitHub Desktop.
Save worldofchris/4664303 to your computer and use it in GitHub Desktop.
Having trouble getting the dojo/request node.js example to work: arnosgrove:example chris$ node example.js module.js:236 var start = request.substring(0, 2); ^ TypeError: Object require,dojo/request has no method 'substring' at Function.Module._resolveLookupPaths (module.js:236:23) at Function.Module._resolveFilename (module.js:328:31) at Functi…
// dojo-release-1.8.3-src is installed in the same directory as this script
dojoConfig = {
baseUrl: ".",
packages:[{name: 'dojo', location: 'dojo'}],
deps:['dojo/request', 'dojo/date']
};
require('./dojo/dojo.js');
// Following is taken from:
// https://dojotoolkit.org/reference-guide/1.8/dojo/request/node.html#id5
require(['require', 'dojo/request'], function(require, request){
var http = require.nodeRequire('http'),
timeout;
var server = http.createServer(function(request, response){
var body = '{ "foo": "bar" }';
response.writeHead(200, {
'Content-Length': body.length,
'Content-Type': 'application/json'
});
response.write(body);
response.end();
});
server.on('close', function(){
if(timeout){ clearTimeout(timeout); }
});
server.on('listening', function(){
request.get('http://localhost:8124', {
handleAs: 'json',
headers: { 'Range': '1-2' },
timeout: 1000
}).then(function(data){
console.log(data);
server.close();
}, function(err){
console.log(err);
server.close();
});
});
server.listen(8124);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment