forked from nextup/nextup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
142 lines (127 loc) · 3.75 KB
/
app.js
File metadata and controls
142 lines (127 loc) · 3.75 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var mongoose = require('mongoose');
var docFetch = require('./docFetch');
var cypherURL = process.env.CYPHER || "http://localhost:7474/db/data/cypher";
var batch = require('./batchOp');
var readURL = require('./scrape.js');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.json());
app.use(express.urlencoded());
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', function(req, res) {
// routes.index;
docFetch.randNodeFetch(cypherURL, 25)
.then(function(result) {
return res.send(result);
});
});
app.get('/users', user.list);
// app.get('/article/*', function(req, res) {
// var fullUrl = req.url;
// var articleUrl = fullUrl.slice(fullUrl.indexOf("http"));
// var mongoURL = { url: articleUrl };
// var response = [];
// readURL.Site.find(mongoURL)
// .exec(function(err, result) {
// if (result.length === 0) {
// console.log("Not in mongo");
// readURL.readSiteByUrl(articleUrl)
// .then(function(readJSON) {
// response.push(readJSON);
// return response;
// })
// .then(function() {
// return docFetch.cosSimFetch(cypherURL, articleUrl, 0.0, 10);
// })
// .then(function(topCosSim) {
// return response.push(topCosSim);
// })
// .then(function() {
// return res.send(response);
// });
// } else {
// console.log("Found in mongo");
// response.push(result);
// docFetch.cosSimFetch(cypherURL, articleUrl, 0.0, 10)
// .then(function(topCosSim) {
// response.push(topCosSim);
// return res.send(response);
// //res.render('index', )
// });
// }
// });
// });
app.post('/article', function(req, res) {
var request = { title: req.body.title, url: req.body.url };
var mongoURL = { url: request.url };
var articleUrl = request.url;
var response = [];
console.log(request);
if (!batch.isInNeo4j(request, batch.masterDoclist)) {
console.log("DOES THIS EVEN WORK?!?!");
return res.send("Invalid Request");
}
readURL.Site.find(mongoURL)
.exec(function(err, result) {
if (result.length === 0) {
console.log("Not in mongo");
readURL.readSiteByUrl(articleUrl)
.then(function(readJSON) {
response.push(readJSON);
return response;
})
.then(function() {
return docFetch.cosSimFetch(cypherURL, articleUrl, 0.0, 25);
})
.then(function(topCosSim) {
return response.push(topCosSim);
})
.then(function() {
return res.send(response);
});
} else {
console.log("Found in mongo");
response.push(result);
docFetch.cosSimFetch(cypherURL, articleUrl, 0.0, 25)
.then(function(topCosSim) {
response.push(topCosSim);
return res.send(response);
});
}
});
});
app.get('/all/neo4j', function(req, res) {
docFetch.allDocFetch(cypherURL)
.then(function(result) {
return res.send(result);
})
.catch(function(error) {
console.log("Errored out ", error);
});
});
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
// require serverInit.js
require('./serverInit.js');