diff --git a/src/bzz-link.ts b/src/bzz-link.ts index 181c04e..2117ccd 100644 --- a/src/bzz-link.ts +++ b/src/bzz-link.ts @@ -1,14 +1,9 @@ import * as swarmCid from '@ethersphere/swarm-cid' import { Strings } from 'cafe-utility' -import { Request } from 'express' import { logger } from './logger' export class NotEnabledError extends Error {} -export function requestFilter(req: Request): boolean { - return req.method === 'GET' && req.subdomains.length >= 1 -} - export function subdomainToBzz( requestHostname: string, appHostname: string, diff --git a/src/proxy.ts b/src/proxy.ts index 191d349..53bfc1d 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -2,7 +2,7 @@ import axios from 'axios' import { Dates, Objects, Strings } from 'cafe-utility' import { Application, Response } from 'express' import { IncomingHttpHeaders } from 'http' -import { requestFilter, subdomainToBzz } from './bzz-link' +import { subdomainToBzz } from './bzz-link' import { logger } from './logger' import { StampsManager } from './stamps' import { getErrorMessage } from './utils' @@ -25,8 +25,10 @@ interface Options { export function createProxyEndpoints(app: Application, options: Options) { app.use(async (req, res, next) => { - if (!options.hostname || !requestFilter(req)) { + if (!options.hostname || !Strings.before(req.hostname, options.hostname) || req.method !== 'GET') { next() + + return } const newUrl = subdomainToBzz( req.hostname, diff --git a/test/bzz-link.spec.ts b/test/bzz-link.spec.ts index 9d9b8c7..3e46372 100644 --- a/test/bzz-link.spec.ts +++ b/test/bzz-link.spec.ts @@ -1,27 +1,6 @@ -import { Request } from 'express' -import { NotEnabledError, requestFilter, subdomainToBzz } from '../src/bzz-link' +import { NotEnabledError, subdomainToBzz } from '../src/bzz-link' describe('bzz.link', () => { - describe('requestFilter', () => { - it('should return true for subdomain', async () => { - const req = { subdomains: ['someEnsName'] } as Request - - expect(requestFilter(req)).toStrictEqual(true) - }) - - it('should return true for multilevel subdomain', async () => { - const req = { subdomains: ['swarm', 'book'] } as Request - - expect(requestFilter(req)).toStrictEqual(true) - }) - - it('should return false for no subdomain', async () => { - const req = { subdomains: [] as string[] } as Request - - expect(requestFilter(req)).toStrictEqual(false) - }) - }) - describe('routerClosure', () => { const MANIFEST = { cid: 'bah5acgzamh5fl7emnrazttpy7sag6utq5myidv3venspn6l5sevr4lko2n3q',