-
-
Save wbobeirne/3e49d6fcf4621c23764ecb4d1457cd32 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
app.post('/api/posts', async (req, res, next) => { | |
try { | |
const { name, content } = req.body; | |
if (!name || !content) { | |
throw new Error('Fields name and content are required to make a post'); | |
} | |
const post = postsManager.addPost(name, content); | |
const invoice = await node.addInvoice({ | |
memo: `Lightning Posts post #${post.id}`, | |
value: content.length, | |
expiry: '120', // 2 minutes | |
}); | |
res.json({ | |
data: { | |
post, | |
paymentRequest: invoice.paymentRequest, | |
}, | |
}); | |
} catch(err) { | |
next(err); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment