Skip to content

Commit 5fc4c74

Browse files
committed
fix: tweak catalog handler
1 parent 8bd55a3 commit 5fc4c74

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/routes/catalog/handler.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { hasUppercase } from '../../utils/product.js';
1413
import { errorResponse } from '../../utils/http.js';
1514
import lookup from './lookup.js';
1615
import fetch from './fetch.js';
@@ -48,15 +47,13 @@ export default async function handler(ctx, request) {
4847
config,
4948
info: { method },
5049
} = ctx;
51-
// Split the pathname into segments and filter out empty strings
5250
const pathSegments = ctx.url.pathname.split('/').filter(Boolean);
53-
if (pathSegments.length !== 7) {
54-
return errorResponse(404, 'invalid path');
55-
}
56-
5751
const [storeCode, storeViewCode, subRoute, sku] = pathSegments.slice(3);
58-
if (hasUppercase(sku)) {
59-
return errorResponse(400, 'Invalid SKU: SKU cannot contain uppercase letters');
52+
53+
if (!Object.keys(handlers).includes(subRoute)
54+
|| (subRoute === 'products' && !sku)
55+
|| (subRoute === 'lookup' && sku)) {
56+
return errorResponse(404, 'invalid path');
6057
}
6158

6259
Object.assign(config, {

src/utils/auth.js

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export async function assertAuthorization(ctx) {
2525
throw errorWithResponse(403, 'invalid key');
2626
}
2727

28+
if (actual === ctx.env.SUPERUSER_KEY) {
29+
ctx.log.info('acting as superuser');
30+
return;
31+
}
32+
2833
const expected = await ctx.env.KEYS.get(ctx.config.siteKey);
2934
if (!expected) {
3035
throw errorWithResponse(403, 'no key found for site');

wrangler.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ VERSION = "@@VERSION@@"
8282
ENVIRONMENT = "prod"
8383

8484
# [secrets]
85-
# ...
85+
# SUPERUSER_KEY

0 commit comments

Comments
 (0)