Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
fastify-decorators
Advanced tools
This package developed to provide useful typescript decorators to implement RequestHandler pattern with Fastify.
NOTE: Fastify-decorators was developed with fastify ^2.0.0
and may not work with other versions.
via npm:
npm install fastify-decorators --save
via yarn:
yarn add fastify-decorators
index.ts:
import { bootstrap } from 'fastify-decorators';
import fastify = require('fastify');
import { join } from 'path';
// Create Fastify instance
const instance = fastify();
// Register handlers auto-bootstrap
instance.register(bootstrap, {
handlersDirectory: join(__dirname, `handlers`),
handlersMask: /\.handler\./
});
instance.listen(3000);
handlers/sample.handler.ts:
import { GET, RequestHandler } from 'fastify-decorators';
@GET('/sample')
export default class SampleHandler extends RequestHandler {
async handle() {
return 'It works!';
}
}
index.ts:
import { bootstrap } from 'fastify-decorators';
import fastify = require('fastify');
import { join } from 'path';
// Create Fastify instance
const instance = fastify();
// Register handlers auto-bootstrap
instance.register(bootstrap, {
controllersDirectory: join(__dirname, `controllers`),
controllersMask: /\.controller\./
});
instance.listen(3000);
handlers/sample.controller.ts:
import { Controller, GET } from 'fastify-decorators';
@Controller('/sample')
export default class SampleController {
@GET('/')
async handle() {
return 'It works!';
}
}
NOTE: Using decorators require experimentalDecorators
to be enabled in tsconfig.json
bootstrap
is Fastify plugin to autoload all decorated modules
example:
import fastify = require('fastify');
import {bootstrap} from 'fastify-decorators';
const instance = fastify();
instance.register(bootstrap, options)
name | type | required | description |
---|---|---|---|
handlersDirectory | string | yes | Specify directory where handlers are located |
handlersMask | string , RegExp | no | Specify mask for files filter |
prefix | string | no | Specify prefix for routes |
List of available decorators for handlers:
GET
POST
PUT
DELETE
HEAD
OPTIONS
ALL
example:
import { POST, RequestHandler } from 'fastify-decorators';
@POST(options)
export default class SimpleHandler extends RequestHandler {
async handle() {return ''}
}
Also fastify-decorators provides decorator for Controllers implementation:
Controller
decorator uses on classhook
decorator to uses on methods to define Fastify HookController accepts string
as route parameter.
It also possible to passthroughs configuration object in case if complex configuration needed:
name | type | required | description |
---|---|---|---|
route | string | yes | Controller base route |
type | ControllerType enum | no | Define controller behaviour. Default SINGLETON |
name | type | required | description |
---|---|---|---|
name | string | yes | Hook name |
Handler decorators accept srting
as URL parameter.
It also possible to passthroughs configuration object in case if complex configuration needed:
name | type | required | description |
---|---|---|---|
url | string | yes | Route url which will be passed to Fastify |
options | RouteConfig | no | Config for route which will be passed to Fastify |
This project licensed under MIT License
FAQs
Framework aimed to provide useful TypeScript decorators to implement controllers, services and request handlers, built with Fastify.
The npm package fastify-decorators receives a total of 4,559 weekly downloads. As such, fastify-decorators popularity was classified as popular.
We found that fastify-decorators demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.