@@ -20,6 +20,8 @@ global.mongoDisconnected = false;
20
20
global . winston = require ( 'winston' ) ;
21
21
expressWinston = require ( 'express-winston' ) ;
22
22
require ( 'winston-loggly' ) ;
23
+ var slack = require ( 'winston-bishop-slack' ) . Slack ;
24
+ var util = require ( 'util' ) ;
23
25
24
26
global . keys = require ( './database-connect/keys.js' ) ( ) ;
25
27
@@ -36,6 +38,31 @@ global.winston.add(global.winston.transports.Loggly, {
36
38
json : true
37
39
} ) ;
38
40
41
+ // add slack transport if API key found
42
+ if ( global . keys . slackWebHook ) {
43
+ var envVal = process . env [ "IS_STAGING" ] ? 'STAGING' : 'PRODUCTION'
44
+ global . winston . add ( slack , {
45
+ webhook_url : global . keys . slackWebHook ,
46
+ icon_url : "https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/caution-128.png" ,
47
+ channel : "#devlogs" ,
48
+ username : "API ERROR BOT - " + envVal ,
49
+ level : 'error' ,
50
+ handleExceptions : true ,
51
+ customFormatter : function ( level , message , meta ) {
52
+ return { attachments : [ {
53
+ fallback : "An Error occured on API POD in - " + envVal ,
54
+ pretext : "An Error occured on API POD in - " + envVal ,
55
+ color : '#D00000' ,
56
+ fields : [ {
57
+ title : util . format ( ":scream_cat: %s" , 'Critical Error' ) ,
58
+ value : meta . error ,
59
+ short : false
60
+ } ]
61
+ } ] }
62
+ }
63
+ } )
64
+ }
65
+
39
66
global . keyService = require ( './database-connect/keyService.js' ) ;
40
67
41
68
global . q = require ( 'q' ) ;
@@ -161,7 +188,7 @@ global.app.use([
161
188
'/cache/:appId' ,
162
189
'/queue/:appId' ,
163
190
'/push/:appId'
164
- ] , function ( req , res , next ) {
191
+ ] , function ( req , res , next ) {
165
192
//This is the Middleware for authenticating the app access using appID and key
166
193
//check if all the services are loaded first.
167
194
@@ -309,6 +336,8 @@ function attachServices() {
309
336
}
310
337
}
311
338
339
+
340
+
312
341
//Attach all API's
313
342
function attachAPI ( ) {
314
343
@@ -335,15 +364,13 @@ function attachAPI() {
335
364
require ( './api/pages/Page.js' ) ( ) ;
336
365
require ( './api/auth/Auth.js' ) ( ) ;
337
366
338
- global . app . use ( expressWinston . errorLogger ( {
339
- transports : [
340
- new winston . transports . Console ( { json : true , colorize : true } ) ,
341
- new global . winston . transports . Loggly ( { subdomain : global . keys . logglySubDomain , inputToken : global . keys . logToken , json : true , tags : [ "cloudboost-server" ] } )
342
- ]
343
- } ) ) ;
367
+
368
+
344
369
345
370
console . log ( '+++++++++++ API Status : OK ++++++++++++++++++' ) ;
346
371
372
+
373
+
347
374
app . use ( function ( err , req , res , next ) {
348
375
if ( err . status !== 500 ) {
349
376
return next ( ) ;
@@ -372,14 +399,14 @@ function ignoreUrl(requestUrl) {
372
399
373
400
console . log ( "Adding Ingnore URLS...." ) ;
374
401
var ignoreUrl = [ //for the routes to check whether the particular service is active/not
375
- "/api/userService" ,
376
- "/api/customService" ,
377
- "/api/roleService" ,
378
- "/api/status" ,
379
- "/file" ,
380
- "/api/createIndex" ,
381
- "/pages" ,
382
- "/status"
402
+ "/api/userService" ,
403
+ "/api/customService" ,
404
+ "/api/roleService" ,
405
+ "/api/status" ,
406
+ "/file" ,
407
+ "/api/createIndex" ,
408
+ "/pages" ,
409
+ "/status"
383
410
] ;
384
411
385
412
for ( var i = 0 ; i < ignoreUrl . length ; i ++ ) {
@@ -402,7 +429,7 @@ function ignoreUrl(requestUrl) {
402
429
403
430
/*
404
431
Routes:
405
- */
432
+ */
406
433
407
434
app . get ( '/' , function ( req , res ) {
408
435
console . log ( 'INDEX PAGE RETURNED.' ) ;
@@ -415,6 +442,10 @@ app.get('/getFile/:filename', function(req, res) { //for getting any file from r
415
442
res . sendFile ( "resources/" + req . params . filename , { root : __dirname } ) ;
416
443
} ) ;
417
444
445
+
446
+
447
+
448
+
418
449
app . set ( 'port' , 4730 ) ; //SET THE DEFAULT PORT.
419
450
420
451
//Server kickstart:
@@ -790,6 +821,11 @@ function attachCronJobs() {
790
821
try {
791
822
console . log ( "attachCronJobs.." ) ;
792
823
require ( './cron/expire.js' ) ;
824
+ app . use ( function ( req , res , next ) {
825
+
826
+ res . status ( 404 ) . json ( { status : 404 , message : 'The endpoint was not found. Please check.' } ) ;
827
+
828
+ } ) ;
793
829
} catch ( err ) {
794
830
global . winston . log ( 'error' , {
795
831
"error" : String ( err ) ,
0 commit comments