![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@appolo/context
Advanced tools
Request context module for appolo
built with appolo-context and async_hooks
.
new context will be create for every request
npm i @appolo/context
key | Description | Type | Default |
---|---|---|---|
id | id of context injector | string | context |
in config/modules/all.ts
import {ContextModule} from '@appolo/context';
export = async function (app: App) {
await app.module(ContextModule);
}
first define your context using the @context
decorator
import {context} from '@appolo/context';
@context()
export class MyContext {
@inject() env: any;
constructor(req, res) {
}
private _user: string;
public set user(value: string) {
this._user = value
}
public get user(): string {
return this._user
}
}
For the example we will define a middleware to set the context data
@define()
@singleton()
export class UserMiddleware extends Middleware {
@inject() context: MyContext;
async run(req, res, next) {
this.context.user = req.query.userName;
next()
}
}
Now we can access the context from any class using @inject context
note that the context is uniq for every request and can not share data between requests
@define()
@singleton()
export class SomeManager {
@inject() context: MyContext ;
public async getName():Promise<string>{
return this.context.user;
}
}
In the controller we will put the middleware and access the manager to get the context name
@controller()
export class ContextController extends Controller {
@inject() someManager: Manager;
@get("/test/context/")
@validation("userName", validator.string().required())
@middleware(UserMiddleware)
async test(req: IRequest, res: IResponse) {
let userName = await this.someManager.getName()
return {userName}
}
}
You can also access the current context from getContext
function
import {getContext} from '@appolo/context';
@define()
@singleton()
export class SomeManager {
public async getName():Promise<string>{
return getContext().user;
}
}
FAQs
appolo context module
We found that @appolo/context demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.