Last active
August 10, 2021 17:59
-
-
Save ernestofreyreg/e4b91cf5b280772dcb42038a2741c300 to your computer and use it in GitHub Desktop.
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
import { isValidEmail } from 'lib/email' | |
import { NextApiRequest, NextApiResponse } from 'next' | |
import nc from 'next-connect' | |
// THIS IS IN MEMORY STATE | |
// will reset on every app restart | |
const subs = [] | |
export default nc<NextApiRequest, NextApiResponse>() | |
.get(async (req, res) => { | |
return res.json(subs) | |
}) | |
.post(async (req, res) => { | |
if (!isValidEmail(req.body.email)) { | |
return res.status(400).json({ error: 'invalid-email' }) | |
} | |
subs.push({ email: req.body.email, updated: Date.now() }) | |
return res.status(204).end() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment