-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (62 loc) · 2.39 KB
/
app.js
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
var Client = require('mongodb').MongoClient;
var fs = require('fs');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({extended : true}));
app.get('/', function(req,res){
res.redirect('http://sodeok.xyz');
});
app.get('/cnt', function(req, res, next) {
res.redirect('/index.html');
});
app.post('/count', function(req, res){
var gte = Number(req.body.gte);
var lt = Number(req.body.lt);
Client.connect('mongodb://localhost:27017/yagall', function(error, db) {
if(error) console.log(error);
else {
db.collection('drop').find({num:{'$gte':gte,'$lt':lt}}).count(function(err, cnt){
if(err) console.log(err);
res.send(String(cnt));
});
db.close();
}
});
});
app.post('/keyword', function(req, res){
var gte = Number(req.body.gte);
var lt = Number(req.body.lt);
Client.connect('mongodb://localhost:27017/yagall', function(error, db) {
if(error) console.log(error);
else {
var wordList = new Array() ;
var flag=0;
db.collection('word').aggregate([{$match:{'num':{$gte:gte,$lt:lt}}},{$group:{_id:"$word",count:{$sum:1}}},{$sort:{"count":-1}},{$limit:100}],function(err,doc){
if(err) console.log(err);
if(doc){
doc.forEach(function(tag){
if(flag<20&&String(tag['_id']).length>1){
var filter=String(tag['_id']);
if(filter!="존나"&&filter!="시발"&&filter!="씨발"&&filter!="새끼"&&filter!="진짜"&&filter!="지금"&&filter!="오늘"&&filter!="본인"&&filter!="요즘"){
var data = new Object();
data.word=tag['_id'];
data.cnt=tag['count'];
wordList.push(data);
flag++;
}
}
});
var jsonData = JSON.stringify(wordList) ;
res.send(jsonData);
db.close();
}
});
}
});
});
app.use((req, res, next) => {
res.status(404).redirect('http://sodeok.xyz');
});
app.listen(8000);