Framework
Plugins
Plugins hook into the Root.js server and build. They're added to the plugins list in root.config.ts. The CMS itself is a plugin (cmsPlugin()), and you can write your own. For every hook, see Plugin in the API reference.
configureServer
A plugin's configureServer() hook receives the Express app, so it can add middleware. This plugin redirects /blog to another site, keeping the query string:
ts
// @/root.config.ts
import {defineConfig} from '@blinkk/root';
import {blogRedirectPlugin} from './plugins/blog-redirect';
export default defineConfig({
plugins: [blogRedirectPlugin()],
});
ts
// @/plugins/blog-redirect.ts
import {NextFunction, Plugin, Request, Response} from '@blinkk/root';
/** Redirects `/blog` to `https://blog.example.com`. */
export function blogRedirectPlugin(): Plugin {
return {
name: 'blog-redirect',
configureServer: (server) => {
server.use((req: Request, res: Response, next: NextFunction) => {
if (req.path.startsWith('/blog')) {
const qIndex = req.originalUrl.indexOf('?');
const query = qIndex === -1 ? '' : req.originalUrl.slice(qIndex);
res.redirect(301, `https://blog.example.com/${query}`);
return;
}
next();
});
},
};
}