-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·65 lines (53 loc) · 1.43 KB
/
Copy pathserver.js
File metadata and controls
executable file
·65 lines (53 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var express = require("express"),
app = express(),
fs = require("fs"),
http = require("http"),
querystring = require('querystring'),
port = process.env.PORT || 2500;
app.use(express.json());
app.use(express.urlencoded());
var nextId = 150;
/*
* Root
*/
app.all("/", function(req, res)
{
console.log("Someone hit us.");
var json = req.body;
var buffer = new Buffer(json.image, 'base64');
var path = "./glass-pics/";
var filename = "glassImage_"+nextId+".jpg";
fs.writeFile(path+filename, buffer, function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
var options = {
hostname: 'localhost',
port: 2800,
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
};
var reqSearcher = http.request(options, function(result) {
result.on('data', function (chunk) {
var result = chunk.toString();
console.log("We are sending back: "+ result);
res.send(result);
});
});
reqSearcher.on('error', function(e) {
console.log("Error: " + e.message);
console.log( e.stack );
});
reqSearcher.write(JSON.stringify({"filename":path+filename}));
//reqSearcher.write(JSON.stringify({"filename":path+"glassImage_128.jpg"}));
reqSearcher.end();
nextId++;
}
});
});
app.listen(port);
console.log("Listening on port " + port);