Created
January 30, 2019 00:58
-
-
Save THEozmic/b13c77faa138dbfcf34992f6e6f361f3 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
import '../utils/db' | |
import Posts from './postsModel' | |
import { respondWith } from '../utils' | |
export const handler = async (event, context) => { | |
context.callbackWaitsForEmptyEventLoop = false | |
if (event.httpMethod !== 'GET') return respondWith({ statusCode: 200 }) | |
try { | |
const posts = await Posts.find().sort({ createdAt: 'desc' }), | |
response = { | |
msg: "Posts successfully found", | |
posts: posts | |
} | |
return respondWith({ statusCode: 200, response }) | |
} catch (err) { | |
console.log(err) // output to netlify function log | |
return respondWith({ statusCode: 500, response: { msg: err.message } }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment