Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
], safe.sure(cb, function () {
// Set up Raven
ctx.locals.ravenjs = new raven.Client('http://blah:blah@localhost/collect/sentry/'+self_id);
setTimeout(function () {
ctx.locals.ravenjs.captureError(new Error("Tinelic Sentry startup!"));
}, 1000);
require("newrelic").noticeError( new Error("Tinelic NewRelic startup!"));
cb(null,{api:{
getFeed:function (token, p, cb) {
if (ctx.locals.newrelic)
ctx.locals.newrelic.setTransactionName("/webapi/"+(token=="public"?"public":"token")+"/feed/"+p.feed);
feed = p.feed.split(".");
requirejs(["feed/"+feed[0]], function (m) {
m[feed[1]](token,p.params,cb);
},cb);
}
}});
}));
},cb);
app.use((req, res) => {
res.setHeader('Cache-Control', 'public, max-age=60');
res.setHeader('Expires', new Date(Date.now() + (1000 * 60)).toUTCString());
const requestId = req.headers['x-request-id']
// This needs to be generated in the request, not a callback
const timingHeader = newrelic.getBrowserTimingHeader()
if (canPrerenderRequest(req)) {
// Ensure the cache gets busted when new JS is deployed
const cacheKey = cacheKeyForRequest(req, stats.hash)
console.log(`[${requestId}][handler] Attempting to serve pre-rendered markup for path`, req.url, cacheKey)
memcacheClient.get(cacheKey, (err, value) => {
if (value) {
console.log(`[${requestId}][memcache] Cache hit!`, req.url)
const { body, postIds, postTokens, streamKind, streamId } = JSON.parse(value)
trackPostViews(requestId, postIds, postTokens, streamKind, streamId)
res.send(body)
} else {
renderFromServer(req, res, cacheKey, timingHeader)
}
})
} else {
*/
// stringify the whole object so that it can be escaped in one pass
const initialStateJson = JSON.stringify(initialState);
// escape the string
const escapedState = escapeHtml(initialStateJson);
const APP_RUNTIME = {
appContext,
escapedState,
};
// strip
newrelic.startBackgroundTransaction('collect:clearCollections', function transactionHandler() {
const transaction = newrelic.getTransaction();
let dtlw = new Date(Date.now() - ctx.cfg.app.cleanRetention);
let q = { _dt: { $lte: dtlw } };
let collectionsToClear = ['page_errors', 'pages', 'page_reqs', 'actions', 'action_stats', 'action_errors', 'metrics'];
safe.each(collectionsToClear, async ctc => {
await collections[ctc].deleteMany(q);
/* const { deletedCount } = */ await collections[ctc].deleteMany(q);
/*
if (deletedCount > 0)
console.info('cleaned %d documents in collection %s at %s', deletedCount, ctc, new Date());
*/
}, err => {
if (err)
newrelic.noticeError(err);
transaction.end();
});
});
function cleaner() {
newrelic.startBackgroundTransaction('collect:clearCollections', function transactionHandler() {
const transaction = newrelic.getTransaction();
let dtlw = new Date(Date.now() - ctx.cfg.app.cleanRetention);
let q = { _dt: { $lte: dtlw } };
let collectionsToClear = ['page_errors', 'pages', 'page_reqs', 'actions', 'action_stats', 'action_errors', 'metrics'];
safe.each(collectionsToClear, async ctc => {
await collections[ctc].deleteMany(q);
/* const { deletedCount } = */ await collections[ctc].deleteMany(q);
/*
if (deletedCount > 0)
console.info('cleaned %d documents in collection %s at %s', deletedCount, ctc, new Date());
*/
}, err => {
if (err)
newrelic.noticeError(err);
transaction.end();
});
import reactCookie from 'react-cookie'
import bodyParser from 'body-parser'
import { tokenAuth } from '@youversion/js-api'
import { IntlProvider } from 'react-intl'
import moment from 'moment'
import Raven from 'raven'
import planLocales from './locales/config/planLocales.json'
import revManifest from './rev-manifest.json'
const urlencodedParser = bodyParser.json()
const router = express.Router()
const availableLocales = require('./locales/config/availableLocales.json');
const localeList = require('./locales/config/localeList.json');
const getAssetPath = nr.createTracer('fnGetAssetPath', (path) => {
const IS_PROD = process.env.NODE_ENV === 'production';
if (IS_PROD) {
return revManifest[path];
} else {
return path;
}
})
const checkAuth = nr.createTracer('fnCheckAuth', (auth) => {
return new Promise((resolve, reject) => {
if (typeof auth === 'object' && typeof auth.token === 'string') {
// We have a token
try {
const token = auth.token
const tokenData = tokenAuth.decodeToken(token)
const sessionData = tokenAuth.decryptToken(tokenData.token)
const urlencodedParser = bodyParser.json()
const router = express.Router()
const availableLocales = require('./locales/config/availableLocales.json');
const localeList = require('./locales/config/localeList.json');
const getAssetPath = nr.createTracer('fnGetAssetPath', (path) => {
const IS_PROD = process.env.NODE_ENV === 'production';
if (IS_PROD) {
return revManifest[path];
} else {
return path;
}
})
const checkAuth = nr.createTracer('fnCheckAuth', (auth) => {
return new Promise((resolve, reject) => {
if (typeof auth === 'object' && typeof auth.token === 'string') {
// We have a token
try {
const token = auth.token
const tokenData = tokenAuth.decodeToken(token)
const sessionData = tokenAuth.decryptToken(tokenData.token)
resolve({
token,
isLoggedIn: true,
isWorking: false,
userData: sessionData,
user: sessionData.email,
password: null,
errors: {
store =>
// create tracer and immediately invoke the resulting function.
// trace should start before rendering, finish after rendering
newrelic.createTracer('serverRender', getRouterRenderer)({
routes,
store,
location: url,
basename,
scripts,
cssLinks,
userAgent,
}) // immediately invoke callback
);
return Object.assign({}, defaultConfig, config)
})
const loadData = nr.createTracer('fnLoadData', (feature, params, startingState, sessionData, store, Locale) => {
return new Promise(nr.createTracer('fnLoadData::promise', (resolve) => {
let fn = null
try {
fn = require(`./app/standalone/${feature}/loadData`).default
resolve(fn(params, startingState, sessionData, store, Locale))
} catch (ex) {
resolve()
}
}))
})
const getLocale = nr.createTracer('fnGetLocale', (languageTag) => {
let final = {}
if (typeof languageTag === 'undefined' || languageTag === null || languageTag === '' || typeof availableLocales[languageTag] === 'undefined') {
final = { locale: availableLocales['en-US'], source: 'default' }
} else {
final = { locale: availableLocales[languageTag], source: 'param' }
}
// Get the appropriate set of localized strings for this locale
final.messages = require(`./locales/${final.locale}.json`);
for (const lc of localeList) {
if (lc.locale === final.locale) {
final.locale2 = lc.locale2
final.locale3 = lc.locale3
final.momentLocale = lc.momentLocale
store =>
// create tracer and immediately invoke the resulting function.
// trace should start before rendering, finish after rendering
newrelic.createTracer('serverRender', getRouterRenderer)({
request,
h,
appContext,
routes: resolvedRoutes,
store,
scripts,
cssLinks,
}) // immediately invoke callback
);