-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
73 lines (61 loc) · 1.82 KB
/
index.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
"use strict"
var express = require('express')
var request = require('request')
var bodyParser = require('body-parser')
var stream = require("stream")
var app = express();
app.set('port', (process.env.PORT || 5000))
app.use(express.static(__dirname + '/public'))
app.get('/', function(request, response) {
response.send('OK')
})
var request_to_horn = function(id,res){
var url = "https://integram.org/" + id;
return request.post({ url: url},function (error, response, body) {
res.statusCode = error ? 500 : 200;
res.send( body)
})
};
app.post('/direct/:id', function(req, res) {
var id = req.params.id;
req.pipe( request_to_horn(id,res) );
})
var textRawParser = bodyParser.text();
app.post('/test-horn/:id', textRawParser , function(req, res) {
var id = req.params.id;
var url = "https://integram.org/" + id;
var raw = req.body;
var post_json = JSON.stringify({text:raw});
var stream = require("stream")
var a = new stream.PassThrough()
a.write(post_json)
a.pipe( request_to_horn(id,res) )
a.end()
})
app.post('/horn/:id', bodyParser.json() , function(req, res) {
var id = req.params.id;
var url = "https://integram.org/" + id;
var json = req.body;
var pre;
if(json.level=='error' || json.level=='fatal'){
pre = "👺 "
}else if( json.level=='info' ){
pre = "⭐ "
}else if( json.level=='warning' || json.level=='debug' ){
pre = "👻 "
}else{
pre = "👻 "
}
pre += `[${json.level}]`
var msg = json.message ;
var link = `${json.url} (${json.project})`
var post_json = JSON.stringify({text:`${pre} ${msg} \n ${link}`});
//console.log(post_json);
var a = new stream.PassThrough()
a.write(post_json)
a.pipe( request_to_horn(id,res) )
a.end()
})
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
})