npm install revane-fastify --save
const RevaneFastify = require('revane-fastify');
const BeanProvider = require('revane-ioc');
const beanProvider = new BeanProvider({
basePackage: __dirname
});
const options = {
port: 3000
};
const revaneFastify = new RevaneFastify(options, beanProvider);
return revaneFastify
.setNotFoundHandler((err, request, reply) => {
// ...
})
.setErrorHandler((request, reply) => {
// ...
})
.register('something')
.register((instance, opts, next) => {
// ...
next()
})
.after((err) => {
// ...
})
.ready((err, instance) => {
// ...
})
.listen()
.then((address) => {
// ...
});
The host that will passed to fastify
.
The port that will passed to fastify
.
If set to true
no information about the application will be logged. Defaults to false
.
Allows to add a middleware.
Note: This will be executed asynchronous.
Allows to add a fastify
plugin.
Note: This will be executed asynchronous.
Selects a bean by id and adds it to the fastify
server.
Note: This will be executed asynchronous.
Registers all beans decorated with @Controller()
.
Note: This will be executed asynchronous.
Starts listening on the configured host/port. Returns a Promise.
Closes the server. Returns a Promise.
Returns the port of the server.
Calls the handler
function when all olugins have been loaded.
Note: This will be executed asynchronous.
Adds an error handler.
fastifyRevane.setErrorHandler((error, request, reply) => {
// ...
})
Note: This will be executed asynchronous.
Adds a page not found handler.
fastifyRevane.setNotFoundHandler((error, request, reply) => {
// ...
})
Note: This will be executed asynchronous.
Executes the handler
function after the current plugin has been added.
Note: This will be executed asynchronous.
It is possible to create controllers using decorators.
import { Get, Param } from 'revane-fastify'
class UserController {
@Get('/user/:id')
getUser (@Param id) {
return {
id
}
}
@Get('/users/')
getUsers () {
return []
}
}
There are decorators for the http methods:
Furthermore there are decorators that provide information from the request
and the reply
itself.
Query
Cookie
Param
Body
Header
Reply
Log
Headers
Params
QueryParameters
RequestBody
Cookies