Skip to content

Commit 358a4e2

Browse files
Merge pull request #189 from CloudBoost/staging
Staging
2 parents d676863 + 9b1320f commit 358a4e2

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

database-connect/keys.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = function (){
1818
globalSettings : "_Settings",
1919
analyticsKey : "109eb359-3d22-4165-9e21-21439637f975",
2020
logToken : "c064fc7e-4fc6-41e6-b51f-32c30deafdcc",
21-
logglySubDomain : "cloudboost"
21+
logglySubDomain : "cloudboost",
22+
slackWebHook : process.env['SLACK_WEBHOOK']
2223
};
2324
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"uuid": "^2.0.1",
6565
"web-push": "^2.1.1",
6666
"winston": "^1.1.2",
67+
"winston-bishop-slack": "^0.2.1",
6768
"winston-loggly": "^1.1.0",
6869
"wns": "^0.5.3"
6970
},

server.js

+52-16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ global.mongoDisconnected = false;
2020
global.winston = require('winston');
2121
expressWinston = require('express-winston');
2222
require('winston-loggly');
23+
var slack = require('winston-bishop-slack').Slack;
24+
var util = require('util');
2325

2426
global.keys = require('./database-connect/keys.js')();
2527

@@ -36,6 +38,31 @@ global.winston.add(global.winston.transports.Loggly, {
3638
json: true
3739
});
3840

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+
3966
global.keyService = require('./database-connect/keyService.js');
4067

4168
global.q = require('q');
@@ -161,7 +188,7 @@ global.app.use([
161188
'/cache/:appId',
162189
'/queue/:appId',
163190
'/push/:appId'
164-
], function(req, res, next) {
191+
], function(req, res, next) {
165192
//This is the Middleware for authenticating the app access using appID and key
166193
//check if all the services are loaded first.
167194

@@ -309,6 +336,8 @@ function attachServices() {
309336
}
310337
}
311338

339+
340+
312341
//Attach all API's
313342
function attachAPI() {
314343

@@ -335,15 +364,13 @@ function attachAPI() {
335364
require('./api/pages/Page.js')();
336365
require('./api/auth/Auth.js')();
337366

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+
344369

345370
console.log('+++++++++++ API Status : OK ++++++++++++++++++');
346371

372+
373+
347374
app.use(function(err, req, res, next) {
348375
if (err.status !== 500) {
349376
return next();
@@ -372,14 +399,14 @@ function ignoreUrl(requestUrl) {
372399

373400
console.log("Adding Ingnore URLS....");
374401
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"
383410
];
384411

385412
for (var i = 0; i < ignoreUrl.length; i++) {
@@ -402,7 +429,7 @@ function ignoreUrl(requestUrl) {
402429

403430
/*
404431
Routes:
405-
*/
432+
*/
406433

407434
app.get('/', function(req, res) {
408435
console.log('INDEX PAGE RETURNED.');
@@ -415,6 +442,10 @@ app.get('/getFile/:filename', function(req, res) { //for getting any file from r
415442
res.sendFile("resources/" + req.params.filename, {root: __dirname});
416443
});
417444

445+
446+
447+
448+
418449
app.set('port', 4730); //SET THE DEFAULT PORT.
419450

420451
//Server kickstart:
@@ -790,6 +821,11 @@ function attachCronJobs() {
790821
try {
791822
console.log("attachCronJobs..");
792823
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+
});
793829
} catch (err) {
794830
global.winston.log('error', {
795831
"error": String(err),

0 commit comments

Comments
 (0)