Created
June 21, 2020 12:36
-
-
Save kronaemmanuel/b9e8f8eda8e2f9c5777a00e64d591c5e to your computer and use it in GitHub Desktop.
Nivo chart POST request handler
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
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