Skip to content

Commit

Permalink
chore: add logs for invalid writekey and dataplane URL
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Sep 23, 2024
1 parent fb2b740 commit a1d7799
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const jsSdkCdnUrl =
process.env.JS_SDK_CDN || 'https://cdn.rudderlabs.com/v1.1/rudder-analytics.min.js';

const isValidWriteKey = (writeKey) => /^[A-Za-z0-9_]{5,}$/.test(writeKey);
const isValidDataPlaneURL = (dataPlaneUrl) => /^(?!:\/\/)([a-zA-Z0-9-_]{1,63}\.)+[a-zA-Z]{2,6}$/.test(dataPlaneUrl);
const isValidDataPlaneURL = (dataPlaneUrl) =>
/^(?!:\/\/)([a-zA-Z0-9-_]{1,63}\.)+[a-zA-Z]{2,6}$/.test(dataPlaneUrl);

router.get('/load', async (ctx) => {
// only takes in writeKey and DataPlane Url
Expand All @@ -37,13 +38,14 @@ router.get('/load', async (ctx) => {
console.log('writeKey', writeKey);
console.log('dataplaneUrl', dataPlaneUrl);
if (!isValidDataPlaneURL(dataPlaneUrl) || !isValidWriteKey(writeKey)) {
console.log(`writeKey:${writeKey} or dataPlaneUrl:${dataPlaneUrl} is invalid or missing`);
ctx.response.body = {
error: 'writeKey or dataPlaneUrl is invalid or missing',
};
ctx.status = 400;
return ctx;
}

d = d.replace('writeKey', writeKey);
d = d.replace('dataPlaneUrl', dataPlaneUrl);
d = d.replace('configBackendUrl', configUrl);
Expand Down

0 comments on commit a1d7799

Please sign in to comment.