Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const app = micro(async (req, res) => {
const end = responseTimer.startTimer();
const reqUrl = url.parse(req.url);
if (reqUrl.pathname === '/metrics') {
return client.register.metrics();
}
if (reqUrl.pathname === '/hystrix.stream') {
res.setHeader('Content-Type', 'text/event-stream;charset=UTF-8');
res.setHeader(
'Cache-Control',
'no-cache; no-store; max-age=0; must-revalidate'
);
res.setHeader('Pragma', 'no-cache');
return Brakes.getGlobalStats().getHystrixStream();
}
requestCount.inc();
requestGauge.inc();
worldCupFixtures
.runWith({
apiBase: API_BASE,
apiToken: API_TOKEN,
timeout: TIMEOUT,
})
.fork(
e => {
requestGauge.dec(); // Need to have this in both branches otherwise leaks be happenin'
end();
send(res, e.status || 500, {
onModuleInit(): any {
const Brakes = require('brakes');
this.globalStats = Brakes.getGlobalStats();
}
export const configHystrix = () => {
if (process.env.STREAM_HYSTRIX === 'true') {
const globalStats = Brakes.getGlobalStats();
http
.createServer((req, res) => {
res.setHeader('Content-Type', 'text/event-stream;charset=UTF-8');
res.setHeader(
'Cache-Control',
'no-cache, no-store, max-age=0, must-revalidate'
);
res.setHeader('Pragma', 'no-cache');
globalStats.getHystrixStream().pipe(res);
})
.listen(3001, () => {
console.log('---------------------');
console.log('Hystrix Stream now live at localhost:3001/hystrix.stream');
console.log('---------------------');
});
}