forked from warsclon/acra-node-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appAcra.js
55 lines (44 loc) · 1.69 KB
/
appAcra.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
var express = require('express');
var colors = require('colors');
var prop = require('./properties.js');
var logger = require('./logger');
var app = express();
app.configure(function () {
app.use(express.logger('default')); /* 'default', 'short', 'tiny', 'dev' */
app.use(express.bodyParser());
});
app.use(express.static(__dirname + '/public'));
app.use(express.favicon());
app.use(express.cookieParser());
app.use(express.cookieSession({
key:prop.key,
secret :prop.secret,
cookie:{ path: '/', httpOnly: true, maxAge: null }
}));
app.use(clientErrorHandler);
app.use( express.bodyParser());
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(app.router);
//function control errors
function clientErrorHandler(err, req, res, next) {
console.log('client error handler found in ip:'+req.ip, err);
res.status(500);
res.render('error', {locals: {"error":err} });
}
var basicAuth = express.basicAuth(function(username, password) {
return (username == prop.username && password == prop.password);
}, 'Restrict area, please identify');
//Mobile without auth
app.post('/logs/:appid', logger.addLog);
//Administration with auth
app.get('/logs/:appid/:id', basicAuth, logger.findByIdDetail);
app.get('/logsexport/:appid/:id', basicAuth, logger.findByIdDetailExport);
app.get('/logs/:appid', basicAuth, logger.findAll);
app.get('/logsexport/:appid', basicAuth, logger.findAllExport);
app.get('/mobiles', basicAuth, logger.findAllCollections);
app.get('/logs/:appid/:id/delete', basicAuth, logger.deleteLog);
app.get('/logout', logger.logout);
console.log("------------------".yellow);
app.listen(prop.portWeb);
console.log('Listening on port '.yellow+prop.portWeb.red);