Plugins
Custom
Create Plugin

Create Plugin

In zely, you can expand the server through plugins.

#Basic Plugin

There is a simple plugin that prints the URL from request.

Typescript
export function myPlugin() {
  return {
    name: 'my-plugin',
 
    // You can access the server
    // by adding middleware to the zely server through server().
    server(server) {
      server.use((req, res, next) => {
        console.log(req.url);
        next();
      });
    },
  };
}

And regist the plugin to configure file.

zely.config.ts
import { myPlugin } from './myplugin';
 
export default defineConfig({
  plugins: [myPlugin()],
});

Now, when you start the app, the URL from request will be displayed for each request!

#Plugin Options

plugin.name

This is the name of the plugin. This is useful for debugging.

plugin.config

You can change the settings.
This value will be executed before the server starts.

plugin.server

You can expand your server by receiving a server instance.

Typescript
return {
  name: 'simple-plugin',
  server(server) {
    server.use((req, res, next) => next());
  },
};

INFO

zely executes middleware in the following order before showing the page:

  1. plugin.server
  2. middleware extending req, res
  3. config.middlewares or middleware in a specific directory
  4. pages middleware (core middleware showing the pages)