From c581f726e0467acd9788e457ae936be7ab13fa4c Mon Sep 17 00:00:00 2001 From: elrrrrrrr Date: Mon, 17 Jul 2023 14:04:50 +0800 Subject: [PATCH] feat: misc router --- app/port/controller/HomeController.ts | 17 ++++++++++++++++ .../controller/HomeController/misc.test.ts | 20 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/port/controller/HomeController/misc.test.ts diff --git a/app/port/controller/HomeController.ts b/app/port/controller/HomeController.ts index 6334b310..9e3725e6 100644 --- a/app/port/controller/HomeController.ts +++ b/app/port/controller/HomeController.ts @@ -9,9 +9,12 @@ import { } from '@eggjs/tegg'; import { AbstractController } from './AbstractController'; import { CacheService, DownloadInfo, UpstreamRegistryInfo } from '../../core/service/CacheService'; +import { NotFoundError, NotImplementedError } from 'egg-errors'; const startTime = new Date(); +const NOT_IMPLEMENTED = [ '/-/npm/v1/security/audits/quick', '/-/npm/v1/security/advisories/bulk' ]; + // registry 站点信息数据 SiteTotalData // SiteEnvInfo: 环境、运行时相关信息,实时查询 // UpstreamInfo: 上游信息,实时查询 @@ -97,4 +100,18 @@ export class HomeController extends AbstractController { use: performance.now() - ctx.performanceStarttime!, }; } + + @HTTPMethod({ + path: '/*', + method: HTTPMethodEnum.POST, + priority: -Infinity, + }) + async misc(@Context() ctx: EggContext) { + const { path } = ctx; + if (NOT_IMPLEMENTED.includes(path)) { + throw new NotImplementedError(`${ctx.path} not implemented yet`); + } + + throw new NotFoundError(`${ctx.path} not found`); + } } diff --git a/test/port/controller/HomeController/misc.test.ts b/test/port/controller/HomeController/misc.test.ts new file mode 100644 index 00000000..947d4722 --- /dev/null +++ b/test/port/controller/HomeController/misc.test.ts @@ -0,0 +1,20 @@ +import { app, assert } from 'egg-mock/bootstrap'; + +describe('test/port/controller/HomeController/misc.test.ts', () => { + describe('[POST /*] misc()', () => { + it('should 501', async () => { + const res = await app.httpRequest() + .post('/-/npm/v1/security/audits/quick') + .expect(501); + assert.equal(res.body.error, '[NOT_IMPLEMENTED] /-/npm/v1/security/audits/quick not implemented yet'); + }); + + it('should 404', async () => { + const res = await app.httpRequest() + .post('/-/greed/is/good') + .expect(404); + assert.equal(res.body.error, '[NOT_FOUND] /-/greed/is/good not found'); + }); + }); + +});