mirror of
https://github.com/arnaucube/comunicationLeap.git
synced 2026-02-07 03:16:45 +01:00
nodejs with express server, leapmotion for movement control, and threejs for 3d render
This commit is contained in:
67
node_modules/formidable/example/json.js
generated
vendored
Normal file
67
node_modules/formidable/example/json.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
var common = require('../test/common'),
|
||||
http = require('http'),
|
||||
util = require('util'),
|
||||
formidable = common.formidable,
|
||||
Buffer = require('buffer').Buffer,
|
||||
port = common.port,
|
||||
server;
|
||||
|
||||
server = http.createServer(function(req, res) {
|
||||
if (req.method !== 'POST') {
|
||||
res.writeHead(200, {'content-type': 'text/plain'})
|
||||
res.end('Please POST a JSON payload to http://localhost:'+port+'/')
|
||||
return;
|
||||
}
|
||||
|
||||
var form = new formidable.IncomingForm(),
|
||||
fields = {};
|
||||
|
||||
form
|
||||
.on('error', function(err) {
|
||||
res.writeHead(500, {'content-type': 'text/plain'});
|
||||
res.end('error:\n\n'+util.inspect(err));
|
||||
console.error(err);
|
||||
})
|
||||
.on('field', function(field, value) {
|
||||
console.log(field, value);
|
||||
fields[field] = value;
|
||||
})
|
||||
.on('end', function() {
|
||||
console.log('-> post done');
|
||||
res.writeHead(200, {'content-type': 'text/plain'});
|
||||
res.end('received fields:\n\n '+util.inspect(fields));
|
||||
});
|
||||
form.parse(req);
|
||||
});
|
||||
server.listen(port);
|
||||
|
||||
console.log('listening on http://localhost:'+port+'/');
|
||||
|
||||
|
||||
var request = http.request({
|
||||
host: 'localhost',
|
||||
path: '/',
|
||||
port: port,
|
||||
method: 'POST',
|
||||
headers: { 'content-type':'application/json', 'content-length':48 }
|
||||
}, function(response) {
|
||||
var data = '';
|
||||
console.log('\nServer responded with:');
|
||||
console.log('Status:', response.statusCode);
|
||||
response.pipe(process.stdout);
|
||||
response.on('end', function() {
|
||||
console.log('\n')
|
||||
process.exit();
|
||||
});
|
||||
// response.on('data', function(chunk) {
|
||||
// data += chunk.toString('utf8');
|
||||
// });
|
||||
// response.on('end', function() {
|
||||
// console.log('Response Data:')
|
||||
// console.log(data);
|
||||
// process.exit();
|
||||
// });
|
||||
})
|
||||
|
||||
request.write('{"numbers":[1,2,3,4,5],"nested":{"key":"value"}}');
|
||||
request.end();
|
||||
43
node_modules/formidable/example/post.js
generated
vendored
Normal file
43
node_modules/formidable/example/post.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
require('../test/common');
|
||||
var http = require('http'),
|
||||
util = require('util'),
|
||||
formidable = require('formidable'),
|
||||
server;
|
||||
|
||||
server = http.createServer(function(req, res) {
|
||||
if (req.url == '/') {
|
||||
res.writeHead(200, {'content-type': 'text/html'});
|
||||
res.end(
|
||||
'<form action="/post" method="post">'+
|
||||
'<input type="text" name="title"><br>'+
|
||||
'<input type="text" name="data[foo][]"><br>'+
|
||||
'<input type="submit" value="Submit">'+
|
||||
'</form>'
|
||||
);
|
||||
} else if (req.url == '/post') {
|
||||
var form = new formidable.IncomingForm(),
|
||||
fields = [];
|
||||
|
||||
form
|
||||
.on('error', function(err) {
|
||||
res.writeHead(200, {'content-type': 'text/plain'});
|
||||
res.end('error:\n\n'+util.inspect(err));
|
||||
})
|
||||
.on('field', function(field, value) {
|
||||
console.log(field, value);
|
||||
fields.push([field, value]);
|
||||
})
|
||||
.on('end', function() {
|
||||
console.log('-> post done');
|
||||
res.writeHead(200, {'content-type': 'text/plain'});
|
||||
res.end('received fields:\n\n '+util.inspect(fields));
|
||||
});
|
||||
form.parse(req);
|
||||
} else {
|
||||
res.writeHead(404, {'content-type': 'text/plain'});
|
||||
res.end('404');
|
||||
}
|
||||
});
|
||||
server.listen(TEST_PORT);
|
||||
|
||||
console.log('listening on http://localhost:'+TEST_PORT+'/');
|
||||
48
node_modules/formidable/example/upload.js
generated
vendored
Normal file
48
node_modules/formidable/example/upload.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
require('../test/common');
|
||||
var http = require('http'),
|
||||
util = require('util'),
|
||||
formidable = require('formidable'),
|
||||
server;
|
||||
|
||||
server = http.createServer(function(req, res) {
|
||||
if (req.url == '/') {
|
||||
res.writeHead(200, {'content-type': 'text/html'});
|
||||
res.end(
|
||||
'<form action="/upload" enctype="multipart/form-data" method="post">'+
|
||||
'<input type="text" name="title"><br>'+
|
||||
'<input type="file" name="upload" multiple="multiple"><br>'+
|
||||
'<input type="submit" value="Upload">'+
|
||||
'</form>'
|
||||
);
|
||||
} else if (req.url == '/upload') {
|
||||
var form = new formidable.IncomingForm(),
|
||||
files = [],
|
||||
fields = [];
|
||||
|
||||
form.uploadDir = TEST_TMP;
|
||||
|
||||
form
|
||||
.on('field', function(field, value) {
|
||||
console.log(field, value);
|
||||
fields.push([field, value]);
|
||||
})
|
||||
.on('file', function(field, file) {
|
||||
console.log(field, file);
|
||||
files.push([field, file]);
|
||||
})
|
||||
.on('end', function() {
|
||||
console.log('-> upload done');
|
||||
res.writeHead(200, {'content-type': 'text/plain'});
|
||||
res.write('received fields:\n\n '+util.inspect(fields));
|
||||
res.write('\n\n');
|
||||
res.end('received files:\n\n '+util.inspect(files));
|
||||
});
|
||||
form.parse(req);
|
||||
} else {
|
||||
res.writeHead(404, {'content-type': 'text/plain'});
|
||||
res.end('404');
|
||||
}
|
||||
});
|
||||
server.listen(TEST_PORT);
|
||||
|
||||
console.log('listening on http://localhost:'+TEST_PORT+'/');
|
||||
Reference in New Issue
Block a user