Skip to content

Instantly share code, notes, and snippets.

@dioscarey
Last active March 2, 2021 15:48
Show Gist options
  • Save dioscarey/41f9ca56b6c8104abc1ebbe79c836fa9 to your computer and use it in GitHub Desktop.
Save dioscarey/41f9ca56b6c8104abc1ebbe79c836fa9 to your computer and use it in GitHub Desktop.
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment