Skip to content

Instantly share code, notes, and snippets.

@wbobeirne
Last active May 29, 2019 18:13
Show Gist options
  • Save wbobeirne/3e49d6fcf4621c23764ecb4d1457cd32 to your computer and use it in GitHub Desktop.
Save wbobeirne/3e49d6fcf4621c23764ecb4d1457cd32 to your computer and use it in GitHub Desktop.
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