Skip to content

Instantly share code, notes, and snippets.

@kronaemmanuel
Created June 21, 2020 12:36
Show Gist options
  • Save kronaemmanuel/b9e8f8eda8e2f9c5777a00e64d591c5e to your computer and use it in GitHub Desktop.
Save kronaemmanuel/b9e8f8eda8e2f9c5777a00e64d591c5e to your computer and use it in GitHub Desktop.
Nivo chart POST request handler
const storage = require('./storage')
const uuid = require('uuid')
const express = require('express')
const server = express()
server.post('/chart', (req, res) => {
// Get all the data and parameters for the chart
const props = req.body
// Generate a random id for the chart
const id = uuid.v4()
// Generate a URL to access the chart from
const url = `${req.protocol}://${req.get('host')}/render/${id}`
// Store the id, props and url in memory
storage.set(id, {
props,
url,
})
// Send back the id and url
res.status(201).json({ id, url })
})
server.listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment