Exporting multiple functions in middleware plugins

I am looking into using cloudflare plugins to apply middleware. We have multiple functions we would like to chain together. - One option is to create 4 separate repos. One for each plugin, and then chain them together in the application. However this is not a desirable option for us. - the second is to export a single plugin which uses flags to apply the different functions as needed. - We are wondering if we can export multiple functions from a single plugin and import whichever ones are needed, to be chained together in the function. This is the preferred option. Can anybody confirm that this is a viable option, and give advice on how best to do this? Thanks in advance
2 Replies
zingzong1073
zingzong10737mo ago
I would also like to double check some details: - I believe we can chain mutliple plugins like so:
// functions/myPlugin.ts

export const onRequestFunction1 = (context) => {
// Your implementation for the first onRequest function
};

export const onRequestFunction2 = (context) => {
// Your implementation for the second onRequest function
};

export const onRequestFunction3 = (context) => {
// Your implementation for the third onRequest function
};
// functions/myPlugin.ts

export const onRequestFunction1 = (context) => {
// Your implementation for the first onRequest function
};

export const onRequestFunction2 = (context) => {
// Your implementation for the second onRequest function
};

export const onRequestFunction3 = (context) => {
// Your implementation for the third onRequest function
};
and import them like so:
// functions/someRoute.ts

import { onRequestFunction1, onRequestFunction2, onRequestFunction3 } from '@your/cloudflare-plugin';

export const onRequestChain = [
onRequestFunction1,
onRequestFunction2,
onRequestFunction3,
];
// functions/someRoute.ts

import { onRequestFunction1, onRequestFunction2, onRequestFunction3 } from '@your/cloudflare-plugin';

export const onRequestChain = [
onRequestFunction1,
onRequestFunction2,
onRequestFunction3,
];
Can anybody confirm this?