mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
refactor: split backend by context instead of type 'controllers/models/...'
This commit is contained in:
19
app/core/middlewares/container_bindings_middleware.ts
Normal file
19
app/core/middlewares/container_bindings_middleware.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Logger } from '@adonisjs/core/logger';
|
||||
import { HttpContext } from '@adonisjs/core/http';
|
||||
import { NextFn } from '@adonisjs/core/types/http';
|
||||
|
||||
/**
|
||||
* The container bindings middleware binds classes to their request
|
||||
* specific value using the container resolver.
|
||||
*
|
||||
* - We bind "HttpContext" class to the "ctx" object
|
||||
* - And bind "Logger" class to the "ctx.logger" object
|
||||
*/
|
||||
export default class ContainerBindingsMiddleware {
|
||||
handle(ctx: HttpContext, next: NextFn) {
|
||||
ctx.containerResolver.bindValue(HttpContext, ctx);
|
||||
ctx.containerResolver.bindValue(Logger, ctx.logger);
|
||||
|
||||
return next();
|
||||
}
|
||||
}
|
||||
17
app/core/middlewares/log_request.ts
Normal file
17
app/core/middlewares/log_request.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { HttpContext } from '@adonisjs/core/http';
|
||||
import logger from '@adonisjs/core/services/logger';
|
||||
|
||||
export default class LogRequest {
|
||||
async handle({ request }: HttpContext, next: () => Promise<void>) {
|
||||
if (
|
||||
!request.url().startsWith('/node_modules') &&
|
||||
!request.url().startsWith('/inertia') &&
|
||||
!request.url().startsWith('/@vite') &&
|
||||
!request.url().startsWith('/@react-refresh') &&
|
||||
!request.url().includes('.ts')
|
||||
) {
|
||||
logger.debug(`[${request.method()}]: ${request.url()}`);
|
||||
}
|
||||
await next();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user