Skip to content

Commit

Permalink
Merge pull request #17 from AthennaIO/develop
Browse files Browse the repository at this point in the history
fix: fetch global middlewares inside the ioc
  • Loading branch information
jlenon7 authored Apr 6, 2022
2 parents 9b3fd31 + 6f56372 commit 20a273e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "1.1.4",
"version": "1.1.5",
"description": "",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down Expand Up @@ -164,7 +164,7 @@
"dependencies": {
"@athenna/config": "1.0.5",
"@athenna/ioc": "1.0.9",
"@athenna/logger": "1.0.9",
"@athenna/logger": "1.1.1",
"@athenna/http": "1.1.3",
"@secjs/utils": "1.8.0",
"reflect-metadata": "0.1.13",
Expand Down
32 changes: 22 additions & 10 deletions src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class Application {

await this.httpServer.listen(port, host)

this.logger.log(`Http server started on http://${host}:${port}`)
this.logger.success(`Http server started on http://${host}:${port}`)

return this.httpServer
}
Expand Down Expand Up @@ -167,7 +167,7 @@ export class Application {
private preloadFile(filePath: string) {
const { dir, name } = parse(filePath)

this.logger.log(`Preloading ${name} file`)
this.logger.success(`Preloading ${name} file`)

require(`${dir}/${name}${this.extension}`)
}
Expand All @@ -184,7 +184,13 @@ export class Application {
require(`${dir}/${name}${this.extension}`),
)

this.logger.success('Booting the Http Kernel')

const httpKernel = new HttpKernel()

/**
* Using getters because they are possible null
*/
const container = this.getContainer()
const httpServer = this.getHttpServer()

Expand All @@ -210,19 +216,25 @@ export class Application {
/**
* Resolving global middlewares inside the Http server.
*/
httpKernel.globalMiddlewares.forEach(globalMiddleware => {
globalMiddleware = ResolveClassExport.resolve(globalMiddleware)
httpKernel.globalMiddlewares.forEach(Middleware => {
Middleware = ResolveClassExport.resolve(Middleware)

if (!container.hasDependency(`App/Middlewares/${Middleware.name}`)) {
container.bind(`App/Middlewares/${Middleware.name}`, Middleware)
}

Middleware = container.safeUse(`App/Middlewares/${Middleware.name}`)

if (globalMiddleware.handle) {
httpServer.use(globalMiddleware.handle, 'handle')
if (Middleware.handle) {
httpServer.use(Middleware.handle, 'handle')
}

if (globalMiddleware.intercept) {
httpServer.use(globalMiddleware.intercept, 'intercept')
if (Middleware.intercept) {
httpServer.use(Middleware.intercept, 'intercept')
}

if (globalMiddleware.terminate) {
httpServer.use(globalMiddleware.terminate, 'terminate')
if (Middleware.terminate) {
httpServer.use(Middleware.terminate, 'terminate')
}
})
}
Expand Down
6 changes: 4 additions & 2 deletions src/Ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ export class Ignite {
providersNormalized.push(ResolveClassExport.resolve(Provider))
})

providersNormalized.forEach(p => this.logger.log(`Registering ${p.name}`))
providersNormalized.forEach(p =>
this.logger.success(`Registering ${p.name}`),
)

return providersNormalized
}
Expand Down Expand Up @@ -247,7 +249,7 @@ export class Ignite {
preload = normalize(preload)

const { dir, name } = parse(Path.config(preload))
this.logger.log(`Preloading ${name} file`)
this.logger.success(`Preloading ${name} file`)

require(`${dir}/${name}${this.extension}`)
})
Expand Down
30 changes: 20 additions & 10 deletions tests/Stubs/config/logging.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Path } from '@secjs/utils'
import { Color } from '@athenna/logger'

export default {
/*
Expand All @@ -22,31 +23,40 @@ export default {
| Here you may configure the log channels for your application.
|
| Available Drivers: "console", "debug", "file".
| Available Formatters: "context", "debug", "json", "log".
| Available Formatters: "cli", "simple", "nest", "json".
|
*/

channels: {
application: {
driver: 'console',
level: 'INFO',
context: 'Logger',
formatter: 'context',
formatter: 'nest',
streamType: 'stdout',
formatterConfig: {
level: 'INFO',
chalk: Color.cyan,
context: 'Logger',
},
},
debug: {
driver: 'debug',
level: 'DEBUG',
context: 'Debugger',
formatter: 'context',
formatter: 'nest',
namespace: 'api:main',
formatterConfig: {
level: 'DEBUG',
chalk: Color.purple,
context: 'Debugger',
},
},
file: {
driver: 'file',
level: 'INFO',
context: 'Logger',
formatter: 'log',
formatter: 'simple',
filePath: Path.noBuild().logs('athenna.log'),
formatterConfig: {
level: 'INFO',
chalk: Color.cyan,
context: 'Logger',
},
},
},
}

0 comments on commit 20a273e

Please sign in to comment.