Created
May 21, 2017 06:10
-
-
Save michaelrambeau/05f839ed8c008ee55245d437bb149c89 to your computer and use it in GitHub Desktop.
Micro-services
This file contains hidden or 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
require('dotenv').config() | |
const { send } = require('micro') | |
const mongoose = require('mongoose') | |
const Restaurant = require('./models/Restaurant') | |
require('./models/Tag') | |
mongoose.Promise = global.Promise | |
module.exports = (req, res) => { | |
res.setHeader('Access-Control-Allow-Origin', '*') | |
mongoose.connect(process.env.MONGO_URI) | |
Restaurant | |
.find() | |
.populate('tags', 'name') | |
.then(result => send(res, 200, result)) | |
.catch(err => { | |
console.error(err) // eslint-disable-line no-console | |
send(res, 400, err.stack) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment