-
Notifications
You must be signed in to change notification settings - Fork 0
HttpPlugin
Danny edited this page Jun 21, 2022
·
4 revisions
The HTTP plugin is a built-in plugin that comes with a full flow for building HTTP services. The plugin is built on top of Express, and provides a simple solution for building powerful APIs with little effort.
The HTTP service comes with a HTTP service, decorators, interfaces and types, middleware and more. You can find an example of it's usage through this guide about controllers.
- A service for the express web server.
- Multiple method decorators for routes, like GET, POST, PUT, DELETE, etc.
- A middleware interface for authentication.
- Context and response objects for accessing request/response data.
- GZIP and deflate support provided by compression.
- CORS/CSP and other security related support provided by helmet.
- File upload support which is pre-configured, see options below (default is disabled).
- Cache support with generic wrapper, you can support LRU and other variants by adding a new cache wrapper.
- Http catch decorator to allow catching all errors and handling gracefully.
Below is an example of setting up the http plugin with the engine.
import { Engine, HttpPlugin } from '@symbux/turbo';
const engine = new Engine({
autowire: true,
});
engine.use(new HttpPlugin({
port: 80,
}));
Available options below.
Name | Type | Default | Description | Required |
---|---|---|---|---|
port |
number |
null |
The port to listen on. | ✅ |
host |
string |
null |
The host to listen on. | ❎ |
static |
Array<IOptionsStaticItem> |
[] |
❎ | |
cache |
ICache |
undefined |
A cache library that implements Http.ICache . |
❎ |
uploads.enabled |
boolean |
false |
Whether to enable automatic file upload. | ❎ |
uploads.maxFileSize |
number |
52428800 (50MB) |
Max file upload size. | ❎ |
uploads.tempFileDir |
string |
/tmp |
The location of uploaded files. | ❎ |
uploads.debug |
boolean |
false |
Outputs debug information from the plugin for the upload middleware. | ❎ |
uploads.uploadTimeout |
number |
undefined |
Timeout for uploading. | ❎ |
security.trustProxy |
Array<string> |
undefined |
Array of trusted proxies. | ❎ |
security.disablePoweredBy |
boolean |
true |
Disables the "powered-by" header. | ❎ |
security.enableHelmet |
boolean |
false |
Enables the Helmet security middleware for express. | ❎ |
security.helmetOptions |
Record<string, any> |
undefined |
Any options for helmet to be forwarded to the express plugin. | ❎ |
compression.enabled |
boolean |
false |
Enable the compression library for gzip support | ❎ |
compression.options |
CompressionOptions |
undefined |
Options are passed directly to the compression library. | ❎ |
- Controllers
- Middleware
- Autowire
- Plugins
- Tasks
- Fibres
- Authentication
- Registry
- Services
- Dependecy Injection
- Translations (i18n)
- Safe Quit
- Exception Handling
- Event Listener
- Custom Logger
- HTTP Plugin - Built-In
- WS Plugin - Built-In
- Discord Plugin - External
- Vite Plugin - External
- Inspect Plugin - External
- CLI Plugin - External
- Got an issue? Join our Discord
- Need your own plugin? Contact Me
- Have an idea? Let's Discuss
- Want to support me? Buy me a coffee