diff --git a/package.json b/package.json index ffeaa87..f18a8e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/http", - "version": "4.28.0", + "version": "4.29.0", "description": "The Athenna Http server. Built on top of fastify.", "license": "MIT", "author": "João Lenon ", diff --git a/src/commands/RouteListCommand.ts b/src/commands/RouteListCommand.ts index d2f70eb..ce39829 100644 --- a/src/commands/RouteListCommand.ts +++ b/src/commands/RouteListCommand.ts @@ -46,7 +46,7 @@ export class RouteListCommand extends BaseCommand { } table.row([ - route.methods.join('|'), + route.methods.map(m => this.paintMethod(m)).join('|'), route.url, route.name || 'Not found', route.handler.name || 'closure' @@ -56,14 +56,33 @@ export class RouteListCommand extends BaseCommand { table.render() } + /** + * Paint a method by its name. + */ + private paintMethod(method: string) { + const colors = { + GET: this.paint.GET.bold(method), + POST: this.paint.POST.bold(method), + PUT: this.paint.PUT.bold(method), + PATCH: this.paint.PATCH.bold(method), + DELETE: this.paint.DELETE.bold(method), + OPTIONS: this.paint.OPTIONS.bold(method), + HEAD: this.paint.HEAD.bold(method) + } + + return colors[method] + } + /** * Resolve the http routes file. */ private async resolveRoute() { - await Module.resolve( - Config.get('rc.commands.route:list.route', '#routes/http'), - this.getParentURL() + const path = Config.get( + 'rc.commands.route:list.route', + `http.${Path.ext()}` ) + + await Module.resolve(path, this.getParentURL()) } /** diff --git a/tests/unit/commands/RouteListCommandTest.ts b/tests/unit/commands/RouteListCommandTest.ts index c9d485a..fbea584 100644 --- a/tests/unit/commands/RouteListCommandTest.ts +++ b/tests/unit/commands/RouteListCommandTest.ts @@ -15,8 +15,6 @@ export default class RouteListCommandTest extends BaseCommandTest { public async shouldBeAbleToListAllRoutesRegisteredInTheHttpServer({ command }: Context) { const output = await command.run('route:list') - console.log(output.output.stderr) - output.assertSucceeded() output.assertLogged('[ LISTING ROUTES ]') output.assertLogged('GET|HEAD') diff --git a/tests/unit/server/ServerTest.ts b/tests/unit/server/ServerTest.ts index 828d168..7f65ee4 100644 --- a/tests/unit/server/ServerTest.ts +++ b/tests/unit/server/ServerTest.ts @@ -57,7 +57,7 @@ export default class ServerTest { @Test() public async shouldBeAbleToGetTheFastifyVersionFromTheHttpServer({ assert }: Context) { - assert.equal(Server.getFastifyVersion(), '4.26.1') + assert.equal(Server.getFastifyVersion(), '4.26.2') } @Test()