Skip to content

Commit 0362229

Browse files
committed
feat: return default errMsg if searchParams empty
1 parent 0fe554c commit 0362229

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ export default {
6868
},
6969
};
7070

71+
/*
72+
Count searchParam iterations; return if URLSearchParams empty
73+
74+
@arg obj object
75+
@return bool
76+
*/
77+
78+
function isEmpty(obj) {
79+
let i = 0;
80+
for (const key of obj) {
81+
i++;
82+
}
83+
84+
console.log(i);
85+
86+
return ( i === 0 ? true : false )
87+
}
88+
7189
/*
7290
Handle Request
7391
*/
@@ -274,7 +292,7 @@ async function handleRequest(req, env, ctx) {
274292
Check Subdomain Exists
275293
*/
276294

277-
if (ENV_SUBDOMAIN && !pathname.startsWith(`/${ENV_SUBDOMAIN}`) || bIsHostBase) {
295+
if (ENV_SUBDOMAIN && !pathname.startsWith(`/${ENV_SUBDOMAIN}`) || bIsHostBase || isEmpty(searchParams)) {
278296
Logger.dev(env, `query url [${pathname}] does not contain subdomain [${ENV_SUBDOMAIN}] in URL; throwing default error`)
279297
return msgErr
280298
}

0 commit comments

Comments
 (0)