How do I apply global interceptors?
Use the options.interceptors property when starting the application. Interceptors defined here run globally for all routes.
const main = async () => {
const app = await HeronJS.create({ module: AppModule });
await app.listen({
port: 3000,
options: {
interceptors: [ApplyAllControllerInterceptor],
},
});
};How do I change the HTTP server port?
Set the port property in app.listen(). If you do not specify it, HeronJS typically starts on port 3000.
const main = async () => {
const app = await HeronJS.create({ module: AppModule });
await app.listen({
port: 3000,
});
};How do I create a global error handler?
Use the options.globalError property to register an application-wide error interceptor.
const main = async () => {
const app = await HeronJS.create({ module: AppModule });
await app.listen({
port: 3000,
options: {
globalError: GlobalErrorInterceptor,
},
});
};How do I apply a global URI prefix?
Use the options.uri property to add a shared prefix to all routes.
const main = async () => {
const app = await HeronJS.create({ module: AppModule });
await app.listen({
port: 3000,
options: {
uri: '/api',
},
});
};With this configuration, a route such as /todos becomes /api/todos.
How do I apply Express middlewares globally?
Use the options.middlewares property to register Express middleware that should run for all requests.
const main = async () => {
const app = await HeronJS.create({ module: AppModule });
await app.listen({
port: 3000,
options: {
middlewares: [cors(), helmet()],
},
});
};This is useful when you want to apply cross-cutting behavior such as logging, security headers, or request parsing at the application level.
How can I deploy my application?
For production deployments, common options include Docker and PM2. Docker is useful for packaging the application and its runtime environment, while PM2 is useful for process management and restarts.