Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): import route file by full path #171

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <lenon@athenna.io>",
27 changes: 23 additions & 4 deletions src/commands/RouteListCommand.ts
Original file line number Diff line number Diff line change
@@ -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())
}

/**
2 changes: 0 additions & 2 deletions tests/unit/commands/RouteListCommandTest.ts
Original file line number Diff line number Diff line change
@@ -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')
2 changes: 1 addition & 1 deletion tests/unit/server/ServerTest.ts
Original file line number Diff line number Diff line change
@@ -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()