Skip to content

Instantly share code, notes, and snippets.

@toughyear
Created September 15, 2020 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toughyear/4e002cec4f1a66d2578ba4d9759a378d to your computer and use it in GitHub Desktop.
Save toughyear/4e002cec4f1a66d2578ba4d9759a378d to your computer and use it in GitHub Desktop.
NextJS API with Firebase example
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