Created
September 15, 2020 08:04
-
-
Save toughyear/4e002cec4f1a66d2578ba4d9759a378d to your computer and use it in GitHub Desktop.
NextJS API with Firebase 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
import { getData } from "../../helper"; | |
export default async function(req, res) { | |
return new Promise((resolve, reject) => { | |
getData() | |
.then(response => { | |
res.statusCode = 200 | |
res.setHeader('Content-Type', 'application/json'); | |
res.setHeader('Cache-Control', 'max-age=180000'); | |
res.end(JSON.stringify(response)) | |
resolve(); | |
}) | |
.catch(error => { | |
res.json(error); | |
res.status(405).end(); | |
resolve() | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment