The server.events object is a podium public interface used to interact with server events. You can subscribe to events using on() or once(), and emit application events using emit().
Key event types include:
'log' Event
Emits internal server events and application events logged via server.log(). The handler signature is function(event, tags).
event.channel: 'internal' for framework events, 'app' for server.log() events.event.tags: An object where each event.tag is a key and the value is true.
'cachePolicy' Event
Emitted when a cache policy is created via server.cache() or a cached server.method(). The handler signature is function(cachePolicy, cache, segment).
'request' Event
Emits internal request events and application events logged via request.log(). The handler signature is function(request, event, tags).
event.channel: 'app' (from request.log()), 'error' (on 500 status codes), or 'internal' (framework generated).
// Example: Listening for request errors
server.events.on('request', (request, event, tags) => {
if (tags.error) {
console.log(`Request ${event.request} error: ${event.error ? event.error.message : 'unknown'}`);
}
});
// Example: Listening to a specific channel
server.events.on({ name: 'request', channels: 'error' }, (request, event, tags) => {
console.log(`Request ${event.request} failed`);
});