Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getService = () => {
// newrelic cannot be imported in a browser environment.
if (! process.env.BROWSER) {
// Attempt to create newrelic client using vip go package.
try {
const { newrelic, logger } = require('@automattic/vip-go'); // eslint-disable-line global-require
const client = newrelic({
logger: logger('irving:newrelic'),
});
// VIP Go's package can return nothing if newrelic is not instsalled or configured improperly.
if (! client) {
return defaultService;
}
return {
client,
start: () => {},
logError(err) {
client.noticeError(err);
},
logTransaction(method, status, category) {
client.setTransactionName(`${method} ${status} ${category}`);
},
const getService = (namespace) => {
const env = process.env.NODE_ENV;
let service;
/* eslint-disable global-require */
if (! process.env.BROWSER) {
const { logger } = require('@automattic/vip-go');
const log = logger(namespace, {
silent: 'test' === env,
});
// Map log levels to winston log levels in node.
service = Object.keys(defaultService)
.reduce((acc, method) => {
acc[method] = (...messages) => {
// Send error to production monitoring service.
if ('production' === env) {
monitor.logError();
}
log[method](...messages);
};
return acc;
const createDebug = (namespace) => (level, ...messages) => {
let log;
const env = process.env.NODE_ENV;
/* eslint-disable global-require */
if (! process.env.BROWSER) {
const { logger } = require('@automattic/vip-go');
log = logger(namespace, {
silent: 'test' === env,
})[level];
} else {
log = require('debug')(namespace);
}
/* eslint-enable */
// In development the app should crash fast when encountering any errors.
messages.forEach((message) => {
if (message instanceof Error && 'development' === env) {
throw message;
}
});
// Send error to production monitoring service.
// if ('production' === env) {
const getService = () => {
// newrelic cannot be imported in a browser environment.
if (! process.env.BROWSER) {
// Attempt to create newrelic client using vip go package.
try {
const { newrelic, logger } = require('@automattic/vip-go'); // eslint-disable-line global-require
const client = newrelic({
logger: logger('irving:newrelic'),
});
// VIP Go's package can return nothing if newrelic is not instsalled or configured improperly.
if (! client) {
return defaultService;
}
return {
client,
start: () => {},
logError(err) {
client.noticeError(err);
},
logTransaction(method, status, category) {
client.setTransactionName(`${method} ${status} ${category}`);
module.exports = function startServer(app) {
let vipServer;
if ('development' !== NODE_ENV) {
vipServer = server(app, { PORT });
vipServer.listen();
}
return vipServer;
};
const os = require('os');
const fs = require('fs');
const path = require('path');
const key = fs.readFileSync(
path.join(os.homedir(), HTTPS_KEY_PATH),
'utf8'
);
const cert = fs.readFileSync(
path.join(os.homedir(), HTTPS_CERT_PATH),
'utf8'
);
irvingServer = https.createServer({ key, cert }, app);
} else {
irvingServer = server(app, { PORT });
}
return irvingServer;
};