Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
express-decorators
Advanced tools
Readme
NOTE: this has been rewritten for version 1, with some breaking changes
Provides decorators for easily wiring up controller classes to express.js routes. If you you use hapijs and want something similar, then the hapi-decorators project has you covered.
TypeScript definitions are built in.
$ npm install --save express-decorators
import * as web from 'express-decorators';
import myMiddlewareFunction from './middleware';
import express from 'express';
/*** define a controller class ***/
@web.basePath('/hello')
public class TestController {
constructor(target) {
this.target = target;
}
@web.get('/world', myMiddlewareFunction)
async sayHelloAction(request, response) {
response.send(`hello, ${this.target}`);
}
@web.use()
async otherMiddleware(request, response, next) {
// this will get called for every action
}
}
/*** install the routes in an express app ***/
let app = express();
let test = new TestController('world');
web.register(app, test);
/*** now we can go to /hello/world and get 'hello, world' back! ***/
this
is an instance of the class)async
methods) and errors will get handled properlybasePath(path: string)
Class decorator to add a base path to every route defined in the class.
middleware(fn: Middleware)
If fn
is a function, then the function is added as route-specific middleware for the action. Note that the middleware will be bound to the controller instance.
If fn
is a string, then the method with that name will be exectued as route-specific middleware when the action is invoked.
route(method: string, path: string, middleware: Middleware[])
Marks the method as a handler for the specified path and http method. The route
parameter is just passed straight to the relevant express method, so whatever is valid there is valid here.
There are shortcuts for the methods below. I.e., instead of route('get', '/')
you can use get('/')
.
all
delete
(called del
so it compiles)get
options
param
patch
post
put
use
getRoutes(target: Object): Route[]
Gets the route metadata for the target object. Paths are automatically prefixed with a base path if one was defined.
register(router: Express.Router, target: Object)
Registers the routes found on the target object with an express Router instance.
Please feel free to start an issue or offer a pull request.
FAQs
ES2015 decorators for express
The npm package express-decorators receives a total of 203 weekly downloads. As such, express-decorators popularity was classified as not popular.
We found that express-decorators 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.