Skip to content

Commit

Permalink
refactor: remove response from intercept mid and add status
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Mar 31, 2022
1 parent 95304ac commit e8a66d8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 58 deletions.
52 changes: 0 additions & 52 deletions config/logging.ts

This file was deleted.

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": "1.0.5",
"version": "1.0.6",
"description": "The Athenna Http server. Built on top of fastify",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
*/

import { RequestContract } from '../../RequestContract'
import { ResponseContract } from '../../ResponseContract'
import { NextInterceptContract } from './NextInterceptContract'

export interface InterceptContextContract {
request: RequestContract
response: ResponseContract
params: Record<string, string>
queries: Record<string, string>
body: Record<string, any>
status: number
data: Record<string, any>
next: NextInterceptContract
}
5 changes: 2 additions & 3 deletions src/Utils/FastifyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ declare module 'fastify' {

export class FastifyHandler {
static createOnSendHandler(handler: InterceptHandlerContract) {
return (req, res, payload, done) => {
return (req, _res, payload, done) => {
const request = new Request(req)
const response = new Response(res)

if (!req.data) req.data = {}
if (!req.query) req.query = {}
Expand All @@ -42,8 +41,8 @@ export class FastifyHandler {

return handler({
request,
response,
body,
status: _res.statusCode,
params: req.params as Record<string, string>,
queries: req.query as Record<string, string>,
data: req.data,
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/HttpTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@ describe('\n HttpTest', () => {
hello: 'world-intercepted',
})
})

afterEach(() => {
Folder.safeRemove(Path.pwd('config'))
})
})

0 comments on commit e8a66d8

Please sign in to comment.