From 478f1c2fbe2490c47d5a38817b1b987e831b4372 Mon Sep 17 00:00:00 2001 From: Micha Vie Date: Tue, 9 Jan 2024 23:08:44 +0100 Subject: [PATCH] remove app id middleware for collections in favor of having app id in the route --- .../collections/collections.controller.ts | 6 +++--- apps/api/src/middleware/app-id.middleware.ts | 16 ---------------- apps/api/src/public.app.module.ts | 8 ++------ 3 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 apps/api/src/middleware/app-id.middleware.ts diff --git a/apps/api/src/endpoints/collections/collections.controller.ts b/apps/api/src/endpoints/collections/collections.controller.ts index af0d2e2..f745967 100644 --- a/apps/api/src/endpoints/collections/collections.controller.ts +++ b/apps/api/src/endpoints/collections/collections.controller.ts @@ -2,7 +2,7 @@ import { ApiResponse } from '@nestjs/swagger' import { AppService } from '@mvx-monorepo/common' import { DataValue } from './entities/data.value' import { DelegationService } from '@mvx-monorepo/common/delegation' -import { Controller, Get, Headers, NotFoundException, Param } from '@nestjs/common' +import { Controller, Get, NotFoundException, Param } from '@nestjs/common' @Controller() export class CollectionsController { @@ -21,10 +21,10 @@ export class CollectionsController { } // TODO: @UseGuards(NativeAuthGuard) - @Get('/collections/:collection') + @Get('apps/:appid/collections/:collection') @ApiResponse({ status: 200 }) @ApiResponse({ status: 404 }) - async show(@Param('collection') key: string, @Headers('app-id') appId: number) { + async show(@Param('appid') appId: string, @Param('collection') key: string) { const app = await this.appService.getAppById(+appId) if (!app) { diff --git a/apps/api/src/middleware/app-id.middleware.ts b/apps/api/src/middleware/app-id.middleware.ts deleted file mode 100644 index ea52067..0000000 --- a/apps/api/src/middleware/app-id.middleware.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Request, Response, NextFunction } from 'express' -import { Injectable, NestMiddleware } from '@nestjs/common' - -@Injectable() -export class AppIdMiddleware implements NestMiddleware { - use(req: Request, res: Response, next: NextFunction) { - const appId = req.headers['app-id'] || req.query['app-id'] - - if (!appId) { - res.status(400).json({ message: 'App ID (app-id) header or query is required' }) - return - } - - next() - } -} diff --git a/apps/api/src/public.app.module.ts b/apps/api/src/public.app.module.ts index 36154fa..a294fa6 100644 --- a/apps/api/src/public.app.module.ts +++ b/apps/api/src/public.app.module.ts @@ -1,10 +1,8 @@ +import { Module, NestModule } from '@nestjs/common' import { DynamicModuleUtils } from '@mvx-monorepo/common' import { LoggingModule } from '@multiversx/sdk-nestjs-common' -import { AppIdMiddleware } from './middleware/app-id.middleware' -import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common' import { EndpointsServicesModule } from './endpoints/endpoints.services.module' import { EndpointsControllersModule } from './endpoints/endpoints.controllers.module' -import { CollectionsController } from './endpoints/collections/collections.controller' @Module({ imports: [LoggingModule, EndpointsServicesModule, EndpointsControllersModule], @@ -12,7 +10,5 @@ import { CollectionsController } from './endpoints/collections/collections.contr exports: [EndpointsServicesModule], }) export class PublicAppModule implements NestModule { - configure(consumer: MiddlewareConsumer) { - consumer.apply(AppIdMiddleware).forRoutes(CollectionsController) - } + configure() {} }