# Server-side hooks These hooks are called on server-side. ## loadSettings Called from: src/node/server.js Things in context: 1. settings - the settings object Use this hook to receive the global settings in your plugin. ## shutdown Called from: src/node/server.js Things in context: None This hook runs before shutdown. Use it to stop timers, close sockets and files, flush buffers, etc. The database is not available while this hook is running. The shutdown function must not block for long because there is a short timeout before the process is forcibly terminated. The shutdown function must return a Promise, which must resolve to `undefined`. Returning `callback(value)` will return a Promise that is resolved to `value`. Example: ``` // using an async function exports.shutdown = async (hookName, context) => { await flushBuffers(); }; ``` ## pluginUninstall Called from: src/static/js/pluginfw/installer.js Things in context: 1. plugin_name - self-explanatory If this hook returns an error, the callback to the uninstall function gets an error as well. This mostly seems useful for handling additional features added in based on the installation of other plugins, which is pretty cool! ## pluginInstall Called from: src/static/js/pluginfw/installer.js Things in context: 1. plugin_name - self-explanatory If this hook returns an error, the callback to the install function gets an error, too. This seems useful for adding in features when a particular plugin is installed. ## `init_` Called from: `src/static/js/pluginfw/plugins.js` Run during startup after the named plugin is initialized. Context properties: * `logger`: An object with the following `console`-like methods: `debug`, `info`, `log`, `warn`, `error`. ## `expressPreSession` Called from: `src/node/hooks/express.js` Called during server startup just before the [`express-session`](https://www.npmjs.com/package/express-session) middleware is added to the Express Application object. Use this hook to add route handlers or middleware that executes before `express-session` state is created and authentication is performed. This is useful for creating public endpoints that don't spam the database with new `express-session` records or trigger authentication. **WARNING:** All handlers registered during this hook run before the built-in authentication checks, so any handled endpoints will be public unless the handler itself authenticates the user. Context properties: * `app`: The Express [Application](https://expressjs.com/en/4x/api.html#app) object. Example: ```javascript exports.expressPreSession = async (hookName, {app}) => { app.get('/hello-world', (req, res) => res.send('hello world')); }; ``` ## `expressConfigure` Called from: `src/node/hooks/express.js` Called during server startup just after the [`express-session`](https://www.npmjs.com/package/express-session) middleware is added to the Express Application object. Use this hook to add route handlers or middleware that executes after `express-session` state is created and authentication is performed. Context properties: * `app`: The Express [Application](https://expressjs.com/en/4x/api.html#app) object. ## `expressCreateServer` Called from: `src/node/hooks/express.js` Identical to the `expressConfigure` hook (the two run in parallel with each other) except this hook's context includes the HTTP Server object. Context properties: * `app`: The Express [Application](https://expressjs.com/en/4x/api.html#app) object. * `server`: The [http.Server](https://nodejs.org/api/http.html#class-httpserver) or [https.Server](https://nodejs.org/api/https.html#class-httpsserver) object. ## expressCloseServer Called from: src/node/hooks/express.js Things in context: Nothing This hook is called when the HTTP server is closing, which happens during shutdown (see the shutdown hook) and when the server restarts (e.g., when a plugin is installed via the `/admin/plugins` page). The HTTP server may or may not already be closed when this hook executes. Example: ``` exports.expressCloseServer = async () => { await doSomeCleanup(); }; ``` ## eejsBlock_`` Called from: src/node/eejs/index.js Things in context: 1. content - the content of the block This hook gets called upon the rendering of an ejs template block. For any specific kind of block, you can change how that block gets rendered by modifying the content object passed in. Available blocks in `pad.html` are: * `htmlHead` - after `` and immediately before the title tag * `styles` - the style ``s * `body` - the contents of the body tag * `editbarMenuLeft` - the left tool bar (consider using the toolbar controller instead of manually adding html here) * `editbarMenuRight` - right tool bar * `afterEditbar` - allows you to add stuff immediately after the toolbar * `userlist` - the contents of the userlist dropdown * `loading` - the initial loading message * `mySettings` - the left column of the settings dropdown ("My view"); intended for adding checkboxes only * `mySettings.dropdowns` - add your dropdown settings here * `globalSettings` - the right column of the settings dropdown ("Global view") * `importColumn` - import form * `exportColumn` - export form * `modals` - Contains all connectivity messages * `embedPopup` - the embed dropdown * `scripts` - Add your script tags here, if you really have to (consider use client-side hooks instead) `timeslider.html` blocks: * `timesliderStyles` * `timesliderScripts` * `timesliderBody` * `timesliderTop` * `timesliderEditbarRight` * `modals` `index.html` blocks: * `indexCustomStyles` - contains the `index.css` `` tag, allows you to add your own or to customize the one provided by the active skin * `indexWrapper` - contains the form for creating new pads * `indexCustomScripts` - contains the `index.js` `