-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
89 lines (77 loc) · 2.73 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var SummarizerManager = require("node-summarizer").SummarizerManager;
var request = require('request');
const express = require('express');
const path = require('path');
const dotenv = require('dotenv');
dotenv.config();
var PORT = process.env.port || 3000;
server.listen(PORT, function(){
console.log("listening on "+PORT);
}); //listen on port 3000
app.use(express.static(path.join(__dirname, 'client/build')));
var APIMarketplaceClient = require('@collaborizm/apimarket/out').APIMarketplaceClient // for project authentication
const apiMarketplaceClient = new APIMarketplaceClient({
grant_type: 'client_credentials',
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
scope: 'openid'
});
// getValidToken will automatically refresh your access token if it's about to expire
var sendMsg = async (message, to) => {
const resp = await apiMarketplaceClient.simpleSmsSend({
message: message,
fromAddress: process.env.FROM,
toAddress: to,
callbackUrl: 'http://example.com'
})
}
app.get('/send',(req,res) => {
sendMsg(req.query.message, req.query.to)
res.end('success');
})
app.get('/summarize', function (req,res) {
console.log(req.query);
if (req.query.unpunctuated) {
request.post({
headers: {'content-type' : 'application/x-www-form-urlencoded'},
url: "http://bark.phon.ioc.ee/punctuator",
body: "text="+req.query.body
}, function(e, r, b) {
var sentences = req.query.sentences? req.query.sentences : 3;
var Summarizer = new SummarizerManager(b,sentences);
//console.log(Summarizer.getSummaryByFrequency());
res.header('Access-Control-Allow-Origin','*');
res.end(Summarizer.getSummaryByFrequency().summary);
})
} else {
var sentences = req.query.sentences? req.query.sentences : 3;
var Summarizer = new SummarizerManager(req.query.body,sentences);
//console.log(Summarizer.getSummaryByFrequency());
res.header('Access-Control-Allow-Origin','*');
res.end(Summarizer.getSummaryByFrequency().summary);
}
});
app.get('*', (req,res) =>{
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
io.on('connection', function (socket) {
console.log("user connected")
socket.on('disconnect', function() {
console.log("some idiot left lmao");
})
socket.emit('news', { hello: 'world' });
socket.broadcast.emit('broadcast', "hello peeps");
socket.on('my other event', function (data) {
console.log(data);
});
socket.on('message', function(data) {
console.log(data);
io.emit('message', data)
})
socket.on('change color', function(color) {
io.emit('change color', color);
} )
});