Last active
December 6, 2018 17:17
-
-
Save roelvan/411d1887a47c98ce8a35507ccdf3def4 to your computer and use it in GitHub Desktop.
Lambda node micro example
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 { send } = require('micro'); | |
const cors = require('micro-cors')(); | |
const { handleErrors } = require('errors'); | |
const mongo = require('mongo'); | |
const COLLECTION_NAME = 'games_v3'; | |
const handler = async (req, res) => { | |
const db = await mongo(); | |
const games = db.collection(COLLECTION_NAME); | |
const [quizzes, total] = await Promise.all([ | |
games | |
.find({}) | |
.limit(30) | |
.toArray(), | |
games.countDocuments({}) | |
]); | |
send(res, 200, { total, data: quizzes }); | |
}; | |
module.exports = handleErrors(cors(handler)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment