Skip to content

Hook Plugins

Hook plugins allow you to subscribe to events that occur on the CMS.

Your hook plugins should be in src/hooks.

  • Directorysrc
    • Directoryhooks
      • hooks.config.ts
      • example-plugin.ts

See the Hooks Reference for a list of hooks.

example-plugin.ts
import { defineHookPlugin } from '@binaryfrost/snowcms/server';
export default defineHookPlugin({
name: 'test-hooks',
plugin: ({ logger }) => ({
serverStart: ({ port }) => {
logger.log(`Server started on port ${port}`);
},
beforeMediaCreateHook: ({ media }) => {
if (media.fileType === 'application/zip' || media.fileType === 'application/x-zip-compressed') {
throw new ExpressError('ZIP files are not allowed', 400);
}
}
})
});
hooks.config.ts
import { defineHookPluginConfig } from '@binaryfrost/snowcms/server';
import examplePlugin from './example-plugin';
export default defineHookPluginConfig({
plugins: [
examplePlugin
]
});