const db = require('./dbConnection'); const putFunction = require('./controllers/putFunction'); const postFunction = require('./controllers/postFunction'); const YOURMiddleware = require('./YOURMiddleware'); // You can create a private package to make it sharable or you can find a way to share your middleware with other functions. const gcf = new YOURMiddleware() gcf.context({ db }); gcf.use((asdf, next) => { setTimeout(() => { next(); }, 2000) }); const someMiddlewareHere = (ctx, next) => { next(); }; gcf.post('/', someMiddlewareHere, postFunction); gcf.put('/', someMiddlewareHere, putFunction); gcf.get('/', someMiddlewareHere, (ctx) => ctx.respond(200)); gcf.get('/test/:id', (ctx) => { const {id} = ctx.urlMatches; return ctx.respond(200, {id: id}) }); exports.yourFunction = gcf.run;