Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
deferred.promise.then(function() {
var port = ConfigService.get('private.content.port');
app.listen(port);
if (NewRelic) {
LogService.info('New Relic enabled for production');
app.locals.NewRelic = NewRelic.getBrowserTimingHeader();
} else {
LogService.info('New Relic disabled for development');
app.locals.NewRelic = "";
}
LogService.info('Serving on port ' + port);
}, function(err) {
LogService.error('App not listening', err);
logger.error(`[WEBCUBE] [${requestId}] Failed to inject inistal state tag`);
logger.error(ex);
}
try {
if (styleTags) {
entryHtml = entryHtml.replace(RE_LAST_IN_HEAD, `${styleTags}`);
}
} catch (ex) {
logger.error(
`[WEBCUBE] [${requestId}] Failed to inject styled-component tag`
);
logger.error(ex);
}
try {
const afterTitle = (isProductionEnv && getDeployConfig().enableNewRelic
? [newrelic.getBrowserTimingHeader()]
: []
).concat(
helmet
? [
helmet.meta.toString(),
helmet.link.toString(),
helmet.style.toString(),
helmet.script.toString(),
helmet.noscript.toString(),
]
: []
);
if (helmet) {
entryHtml = entryHtml.replace(RE_TITLE, helmet.title.toString());
}
entryHtml = entryHtml.replace(