Last active
March 2, 2021 15:48
-
-
Save dioscarey/41f9ca56b6c8104abc1ebbe79c836fa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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