Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function sewingKitMiddleware(ctx: Context, next: () => Promise) {
const assets = new Assets({
assetPrefix,
userAgent: ctx.get(Header.UserAgent),
manifestPath,
});
setAssets(ctx, assets);
await next();
}
const {body} = ctx.request as any;
if (!isClientMetricsBody(body)) {
ctx.status = StatusCode.UnprocessableEntity;
return;
}
const statsd = new StatsDClient({
host: statsdHost,
port: statsdPort,
logger: statsLogger,
snakeCase: true,
prefix,
});
const userAgent = ctx.get(Header.UserAgent);
const {connection, events, navigations} = body;
const metrics: {
name: string;
value: any;
tags: {[key: string]: string | undefined | null};
}[] = [];
const additionalTags = getAdditionalTags
? getAdditionalTags(body, userAgent)
: {};
const tags = {
browserConnectionType: connection.effectiveType,
...additionalTags,
};