Turbo Mode

What it does

Disables URL pattern matching and match with request method only.

How to use
MicroBootstrap(MyRouter, {
    turboMode: true
})
Description

When turboMode is set to true, URL pattern matching will be disabled and incoming request will only be matched by their request method.

So this:

@MicroMethod('/users/:userId')
getUser(req: MicroRequest, res: MicroResponse): void {
    // You will not be able to use `req.params.userId` in turbo mode
    res.send(req.params.userId) // undefined
}

will be equivalent to:

@MicroMethod()
getUser(req: MicroRequest, res: MicroResponse): void {
    res.send('Bob')
}

// You can still use middleware functions
@MicroMethod(ejwt({secret: 'serverSecret'}))
getUser(req: MicroRequest, res: MicroResponse): void {
    res.send('Authenticated: ' + req.token)
}

NOTE: URL pattern matching is expensive, by turning on turboMode you will get a performance boost as each incoming request will only be mapped based on their request method, e.g: GET, POST etc. Note that when using turboMode, you can only have a maximum of 1 handler per method. This means you cannot have more than a single instance of MicroMethod.Get in your ENTIRE APP! Again, this is optimal for micro-service environments as each service usually handles 1 type of resource.

results matching ""

    No results matching ""