Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
require('dotenv-extended').load();
const config = require('./config');
var appInsights = require("applicationinsights");
if (config.instrumentationKey){
appInsights.setup(config.instrumentationKey)
.setAutoDependencyCorrelation(true)
.setAutoCollectDependencies(true)
.setAutoCollectPerformance(true);
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "calc-backend-svc";
appInsights.start();
}
var client = appInsights.defaultClient;
const express = require('express');
const app = express();
const morgan = require('morgan');
const OS = require('os');
// add logging middleware
app.use(morgan('dev'));
// Routes
app.get('/', function(req, res) {
console.log('received request');
res.send('Hi!');
});
require('dotenv-extended').load();
const config = require('./config');
var appInsights = require("applicationinsights");
if (config.instrumentationKey){
appInsights.setup(config.instrumentationKey)
.setAutoDependencyCorrelation(true)
.setAutoCollectDependencies(true)
.setAutoCollectPerformance(true);
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "calc-backend-svc";
appInsights.start();
}
var client = appInsights.defaultClient;
const express = require('express');
const app = express();
const morgan = require('morgan');
const OS = require('os');
// add logging middleware
app.use(morgan('dev'));
// Routes
app.get('/', function(req, res) {
console.log('received request');
res.send('Hi!');
});
statusCode = 400;
title = 'validation-error'
}
// Problem Details object as per standard https://tools.ietf.org/html/rfc7807
let problemDetails = {
error: true,
title: title,
details: err.toString(),
status: statusCode,
source: source
};
// App Insights
const appInsights = require("applicationinsights");
if(appInsights.defaultClient) appInsights.defaultClient.trackException({exception: err});
res.status(statusCode).send(problemDetails);
}
}
private createClient() {
// check if another instance exists
if (ai.defaultClient) {
this.client = new ai.TelemetryClient(this.aiKey);
this.client.channel.setUseDiskRetryCaching(true);
} else {
ai.setup(this.aiKey)
.setAutoCollectConsole(false)
.setAutoCollectDependencies(false)
.setAutoCollectExceptions(false)
.setAutoCollectPerformance(false)
.setAutoCollectRequests(false)
.setAutoDependencyCorrelation(false)
.setUseDiskRetryCaching(true)
.start();
this.client = ai.defaultClient;
}
this.setCommonProperties();
this.client.context.tags[this.client.context.keys.sessionId] = vscode.env.sessionId;
this.client.context.tags[this.client.context.keys.userId] = vscode.env.machineId;
}
let statusCode = err.code ? err.code : 500;
if(statusCode < 100 || statusCode > 999) statusCode = 500;
// Problem Details object as per https://tools.ietf.org/html/rfc7807
let problemDetails = {
error: true,
title: title,
details: err.toString(),
status: statusCode,
source: source
};
// App Insights
const appInsights = require("applicationinsights");
if(appInsights.defaultClient) appInsights.defaultClient.trackException({apiError: problemDetails});
res.status(statusCode).send(problemDetails);
}
app.use(function(req, res, next) {
/* AppInsights request tracking for GET and POST */
if (req.method === 'GET' || req.method === 'POST') {
appInsights.defaultClient.trackNodeHttpRequest({
request: req,
response: res
});
}
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader(
'Access-Control-Allow-Methods',
'GET, POST, OPTIONS, PUT, PATCH, DELETE'
);
res.setHeader(
'Access-Control-Allow-Headers',
'X-Requested-With,content-type'
);
next();
});
sendData(res, data) {
// App Insights
const appInsights = require("applicationinsights");
if(appInsights.defaultClient) appInsights.defaultClient.trackEvent({name: "dataEvent", properties: {data: JSON.stringify(data)}});
res.status(200).send(data)
return;
}
}
require('dotenv-extended').load();
const config = require('./config');
var appInsights = require("applicationinsights");
if (config.instrumentationKey){
appInsights.setup(config.instrumentationKey)
.setAutoDependencyCorrelation(true)
.setAutoCollectDependencies(true)
.setAutoCollectPerformance(true);
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "calc-frontend";
appInsights.start();
}
var client = appInsights.defaultClient;
const express = require('express');
const app = express();
const morgan = require('morgan');
const request = require('request');
const OS = require('os');
const redis = require("redis");
var redisClient = null;
var publicDir = require('path').join(__dirname, '/public');
// add logging middleware
require('dotenv-extended').load();
const config = require('./config');
var appInsights = require("applicationinsights");
if (config.instrumentationKey){
appInsights.setup(config.instrumentationKey)
.setAutoDependencyCorrelation(true)
.setAutoCollectDependencies(true)
.setAutoCollectPerformance(true);
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "calc-backend-svc";
appInsights.start();
}
var client = appInsights.defaultClient;
const express = require('express');
const app = express();
const morgan = require('morgan');
const OS = require('os');
// add logging middleware
app.use(morgan('dev'));
// Routes
app.get('/', function(req, res) {
db.on('error', err => {
appInsights.defaultClient.trackEvent({ name: 'MongoConnError' });
console.log(err);
});