-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
85 lines (67 loc) · 2.14 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
var express = require('express');
var bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
const config = require('./config.js');
const db = require('./db.js');
const helper = require('./helper.js');
const appModule = require('./module.js');
app.set('view engine', 'ejs');
var collection = '';
db.connect(function () {
collection = db.collection();
});
app.use(express.static(__dirname + '/public')); // placed here to override the all requsts
app.use((err, req, res, next) => {
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
console.error('Bad JSON Format');
}
});
app.get('/', (req, res) => {
res.send('working app..');
});
app.post("/save", (req, res) => {
var response = '', reqData = req.body;
var data = {
url: decodeURIComponent(reqData.url),
file: reqData.file,
line: reqData.line,
column: reqData.column,
error: reqData.error,
createdOn: new Date()
};
appModule.saveData({
db: db,
data: data
}, function (result) {
helper.preparePostOutput(res, reqData, { "searchResult": "SUCCESS" });
});
});
app.get("/show*", (req, res) => {
var response = '', reqData = req.query;
var u = req._parsedUrl.pathname,
template = 'log_error.ejs',
sort = { "createdOn": -1},
query = {};
let pagesize = reqData.pagesize ? parseInt(reqData.pagesize) : 10;
let pageno = reqData.pageno ? parseInt(reqData.pageno) : 1;
appModule.getData({
db:db,
query: query,
sort: sort,
pagesize: pagesize,
pageno: pageno,
}, function(domainResult) {
var finalResult = {};
finalResult.domainResult = domainResult ? domainResult : {};
res.render(template, {result: finalResult.domainResult})
})
});
// And start the server
var server = app.listen(config.appPort, function () {
var host = server.address().address;
var port = server.address().port;
console.log("app listening at http://%s:%s", host, port);
});
server.timeout = config.serverTimeout;