Skip to content

Commit

Permalink
chore(npm): update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Dec 31, 2024
1 parent 935f517 commit e4b95c7
Show file tree
Hide file tree
Showing 12 changed files with 391 additions and 370 deletions.
691 changes: 353 additions & 338 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/http",
"version": "5.8.0",
"version": "5.9.0",
"description": "The Athenna Http server. Built on top of fastify.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down Expand Up @@ -75,19 +75,19 @@
},
"devDependencies": {
"@athenna/artisan": "^5.3.0",
"@athenna/common": "^5.3.0",
"@athenna/common": "^5.4.0",
"@athenna/config": "^5.1.0",
"@athenna/ioc": "^5.0.0",
"@athenna/logger": "^5.1.0",
"@athenna/test": "^5.2.0",
"@athenna/tsconfig": "^5.0.0",
"@athenna/view": "^5.1.0",
"@fastify/cors": "^8.5.0",
"@fastify/helmet": "^11.1.1",
"@fastify/rate-limit": "^8.1.1",
"@fastify/static": "^7.0.4",
"@fastify/swagger": "^8.15.0",
"@fastify/swagger-ui": "^3.1.0",
"@fastify/cors": "^10.0.1",
"@fastify/helmet": "^13.0.0",
"@fastify/rate-limit": "^10.2.1",
"@fastify/static": "^8.0.3",
"@fastify/swagger": "^9.4.0",
"@fastify/swagger-ui": "^5.2.0",
"@fastify/vite": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
Expand Down
2 changes: 1 addition & 1 deletion src/context/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export class Response {
*/
public async redirectTo(url: string, status?: number): Promise<Response> {
if (status) {
await this.response.redirect(status, url)
await this.response.redirect(url, status)

return this
}
Expand Down
10 changes: 7 additions & 3 deletions src/handlers/HttpExceptionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ export class HttpExceptionHandler {
* The exception handler of all request handlers.
*/
public async handle({ error, response }: ErrorContext): Promise<void> {
let code = error.code

if (error.code === undefined) {
code = error.name || 'E_INTERNAL_SERVER'
}

const body: any = {
statusCode: Json.copy(error.statusCode) || Json.copy(error.status) || 500,
code: String.toSnakeCase(
`${error.code}` || error.name || 'E_INTERNAL_SERVER'
).toUpperCase(),
code: String.toSnakeCase(code).toUpperCase(),
name: Json.copy(error.name),
message: Json.copy(error.message),
details: Json.copy(error.details),
Expand Down
5 changes: 4 additions & 1 deletion src/providers/HttpServerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { ServerImpl } from '#src/server/ServerImpl'

export class HttpServerProvider extends ServiceProvider {
public register() {
this.container.instance('Athenna/Core/HttpServer', new ServerImpl())
this.container.instance(
'Athenna/Core/HttpServer',
new ServerImpl(Config.get('http.fastify'))
)
}

public async shutdown() {
Expand Down
2 changes: 1 addition & 1 deletion src/server/ServerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ServerImpl {
public isListening: boolean

public constructor(options?: FastifyServerOptions) {
this.fastify = fastify.fastify(options)
this.fastify = fastify.fastify({ ...options, exposeHeadRoutes: false })
this.isListening = false

this.fastify.decorateReply('body', null)
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/commands/RouteListCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default class RouteListCommandTest extends BaseCommandTest {
public async shouldBeAbleToListAllRoutesRegisteredInTheHttpServer({ command }: Context) {
const output = await command.run('route:list')

console.log(output.output)

output.assertSucceeded()
output.assertLogged('[ LISTING ROUTES ]')
output.assertLogged('GET|HEAD')
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/context/RequestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class RequestTest {
public async shouldBeAbleToGetTheRequestHostname({ assert }: Context) {
const ctx = { request: new Request(this.request) }

assert.equal(ctx.request.hostname, 'localhost:80')
assert.equal(ctx.request.hostname, 'localhost')
}

@Test()
Expand Down
11 changes: 4 additions & 7 deletions tests/unit/kernels/HttpKernelTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default class HttpKernelTest {

assert.deepEqual(response.json(), { hello: true })
assert.containsSubset(response.headers, {
vary: 'Origin',
'access-control-expose-headers': '*'
})
assert.isTrue(Server.fastify.hasPlugin('@fastify/cors'))
Expand All @@ -55,11 +54,9 @@ export default class HttpKernelTest {

assert.deepEqual(response.json(), { hello: true })
assert.containsSubset(response.headers, {
'x-frame-options': 'SAMEORIGIN',
'x-dns-prefetch-control': 'off',
'cross-origin-opener-policy': 'same-origin',
'cross-origin-resource-policy': 'same-origin',
'strict-transport-security': 'max-age=15552000; includeSubDomains'
'x-content-type-options': 'nosniff',
'x-download-options': 'noopen',
'x-xss-protection': '0'
})
assert.isTrue(Server.fastify.hasPlugin('@fastify/helmet'))
}
Expand All @@ -71,7 +68,7 @@ export default class HttpKernelTest {

const response = await Server.request().get('documentation')

assert.equal(response.statusCode, 302)
assert.equal(response.statusCode, 200)
assert.isTrue(Server.fastify.hasPlugin('@fastify/swagger'))
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/router/RouterTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class RouterTest {
}

@Test()
public async shouldBeAbleToRegistryARouteThatWillAutomaticallyRenderAView({ assert }: Context) {
public async shouldBeAbleToRegisterARouteThatWillAutomaticallyRenderAView({ assert }: Context) {
View.createComponent('test', '<h1>{{ name }}</h1>')
Route.view('/test', 'test', { name: 'lenon' })
Route.register()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/server/ServerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class ServerTest {

const routes = Server.getRoutes()

assert.equal(routes, '└── /\n' + ' └── test (GET, HEAD)\n')
assert.equal(routes, '└── /\n' + ' └── test (GET)\n')
}

@Test()
Expand Down Expand Up @@ -57,7 +57,7 @@ export default class ServerTest {

@Test()
public async shouldBeAbleToGetTheFastifyVersionFromTheHttpServer({ assert }: Context) {
assert.equal(Server.getFastifyVersion(), '4.28.1')
assert.equal(Server.getFastifyVersion(), '5.2.0')
}

@Test()
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/testing/plugins/RequestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { Server, HttpServerProvider } from '#src'
import { Test, AfterAll, BeforeAll, type Context } from '@athenna/test'

export default class TestRequestTest {
export default class RequestTest {
@BeforeAll()
public async beforeEach() {
ioc.reconstruct()
Expand All @@ -28,26 +28,26 @@ export default class TestRequestTest {
.send({ hello: 'world', helloo: 'worldd', hellooo: 'worlddd' })
})

Server.get({
url: '/test/array',
Server.head({
url: '/test',
handler: ctx =>
ctx.response
.status(200)
.header('hello', 'world')
.header('helloo', 'worldd')
.header('hellooo', 'worlddd')
.send([{ hello: 'world', helloo: 'worldd', hellooo: 'worlddd' }])
.send({ hello: 'world', helloo: 'worldd', hellooo: 'worlddd' })
})

Server.head({
url: '/test',
Server.get({
url: '/test/array',
handler: ctx =>
ctx.response
.status(200)
.header('hello', 'world')
.header('helloo', 'worldd')
.header('hellooo', 'worlddd')
.send({ hello: 'world', helloo: 'worldd', hellooo: 'worlddd' })
.send([{ hello: 'world', helloo: 'worldd', hellooo: 'worlddd' }])
})

Server.options({
Expand Down

0 comments on commit e4b95c7

Please sign in to comment.