-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-wrapper.js
More file actions
39 lines (32 loc) · 943 Bytes
/
Copy pathserver-wrapper.js
File metadata and controls
39 lines (32 loc) · 943 Bytes
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
var express = require("express"),
app = express(),
fs = require("fs"),
http = require("http"),
port = process.env.PORT || 2800,
Searcher = require('./searcher.js'),
OCRExtractor = require('./ocr-extractor.js');
app.use(express.json());
app.use(express.urlencoded());
var s = new Searcher();
var ocr = new OCRExtractor();
app.all("/", function(req, res)
{
console.log("Some one hit us in server-wrapper.js");
var cb = function(page, left, center, right) {
console.log("We ran cb.");
if ( !page ) {
console.log("Error: send empty result to Glass.");
res.contentType('application/json');
res.send(JSON.stringify({"error": 100}));
} else {
ocr.extract(page, left, center, right, function(json) {
res.contentType('application/json');
json["error"] = "0";
res.send(JSON.stringify(json));
});
}
};
s.match_file(req.body.filename, cb);
});
app.listen(port);
console.log("Listening on port " + port);