Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Database = require('@subfuzion/database').Database;
const express= require('express');
const http = require('http');
const morgan = require('morgan');
const xray = require('aws-xray-sdk-core');
const xrayExpress = require('aws-xray-sdk-express');
xray.middleware.disableCentralizedSampling();
const port = process.env.PORT || 3000;
const app = express();
const server = http.createServer(app);
let databaseConfig = Database.createStdConfig();
let db;
// install route logging middleware
app.use(morgan('dev'));
// install json body parsing middleware
app.use(express.json());
// install x-ray tracing
app.use(xrayExpress.openSegment('database-proxy.app'));
process.env.AWS_XRAY_DEBUG_MODE=1;
const axios = require('axios');
const express= require('express');
const http = require('http');
const morgan = require('morgan');
const port = process.env.PORT || 3000;
const app = express();
const server = http.createServer(app);
const xray = require('aws-xray-sdk-core');
const xrayExpress = require('aws-xray-sdk-express');
xray.middleware.disableCentralizedSampling();
const captureAxios = require('./xray-axios');
let ax = axios.create({
baseURL: process.env.DATABASE_PROXY_URI || 'http://database-proxy:3000/'
});
captureAxios(ax);
// install route logging middleware
app.use(morgan('dev'));
// install json body parsing middleware
app.use(express.json());
// install x-ray tracing
const isProduction = (process.env.NODE_ENV === 'production'); // True on production server.
const functionName = process.env.AWS_LAMBDA_FUNCTION_NAME || 'unknown_function';
const logName = process.env.LOGNAME || 'sigfox-aws';
const stringify = require('json-stringify-safe');
// //////////////////////////////////////////////////////////////////////////////////// endregion
// region Utility Functions
// //////////////////////////////////////////////////////////////////////////////////// endregion
// region Instrumentation Functions: Trace the execution of this Sigfox Callback across multiple Cloud Functions via AWS X-Ray
// Allow AWS X-Ray to capture trace.
// eslint-disable-next-line import/no-unresolved
const AWSXRay = require('aws-xray-sdk-core');
AWSXRay.middleware.setSamplingRules({
rules: [{ description: 'sigfox-aws', service_name: '*', http_method: '*', url_path: '/*', fixed_target: 0, rate: 0.5 }],
default: { fixed_target: 1, rate: 0.5 },
version: 1,
});
// Create the AWS SDK instance.
const AWS = isProduction
? AWSXRay.captureAWS(require('aws-sdk'))
: require('aws-sdk');
if (isProduction) AWS.config.update({ region: process.env.AWS_REGION });
else AWS.config.loadFromPath('./aws-credentials.json');
// TODO: Create spans and traces for logging performance.
const rootSpanStub = {
startSpan: (/* rootSpanName, labels */) => ({
end: () => ({}),
process.env.AWS_XRAY_DEBUG_MODE=1;
const axios = require('axios');
const express= require('express');
const http = require('http');
const morgan = require('morgan');
const port = process.env.PORT || 3000;
const app = express();
const server = http.createServer(app);
const xray = require('aws-xray-sdk-core');
const xrayExpress = require('aws-xray-sdk-express');
xray.middleware.disableCentralizedSampling();
const captureAxios = require('./xray-axios');
let ax = axios.create({
baseURL: process.env.DATABASE_PROXY_URI || 'http://database-proxy:3000/'
});
captureAxios(ax);
// route logging middleware
app.use(morgan('dev'));
// json body parsing middleware
app.use(express.json());
// install x-ray tracing
process.env.AWS_XRAY_DEBUG_MODE=1;
const axios = require('axios');
const express= require('express');
const http = require('http');
const morgan = require('morgan');
const xray = require('aws-xray-sdk-core');
const xrayExpress = require('aws-xray-sdk-express');
xray.middleware.disableCentralizedSampling();
const captureAxios = require('./xray-axios');
const port = process.env.PORT || 3000;
const app = express();
const server = http.createServer(app);
let votesURI = process.env.VOTES_URI || 'http://votes:3000/';
let votesAPI = axios.create({
baseURL: votesURI
});
let reportsURI = process.env.REPORTS_URI || 'http://reports:3000/';
let reportsAPI = axios.create({
baseURL: reportsURI
});
/**
* Express middleware module.
*
* Exposes Express middleware functions to enable automated data capturing on a web service. To enable on a Node.js/Express application,
* use 'app.use(AWSXRayExpress.openSegment())' before defining your routes. After your routes, before any extra error
* handling middleware, use 'app.use(AWSXRayExpress.closeSegment())'.
* Use AWSXRay.getSegment() to access the current sub/segment.
* Otherwise, for manual mode, this appends the Segment object to the request object as req.segment.
* @module express_mw
*/
var AWSXRay = require('aws-xray-sdk-core');
var mwUtils = AWSXRay.middleware;
var IncomingRequestData = mwUtils.IncomingRequestData;
var Segment = AWSXRay.Segment;
var expressMW = {
/**
* Use 'app.use(AWSXRayExpress.openSegment('defaultName'))' before defining your routes.
* Use AWSXRay.getSegment() to access the current sub/segment.
* Otherwise, for manual mode, this appends the Segment object to the request object as req.segment.
* @param {string} defaultName - The default name for the segment.
* @alias module:express_mw.openSegment
* @returns {function}
*/
openSegment: function openSegment(defaultName) {
if (!defaultName || typeof defaultName !== 'string')