From b9c9876032e96d341a5c997f3a79a86775c8242e Mon Sep 17 00:00:00 2001 From: Joeri1983 <96566809+Joeri1983@users.noreply.github.com> Date: Fri, 3 Nov 2023 08:58:57 +0100 Subject: [PATCH] Update index.js --- index.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 54e5fef1f..3923cb161 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,69 @@ const http = require('http'); +const https = require('https'); +const fs = require('fs'); const port = process.env.PORT || 3000; +const azureStorageUrl = 'https://storagejoeri.blob.core.windows.net/dgjoeri/waardes.csv'; + const server = http.createServer((req, res) => { - res.statusCode = 200; - const msg = 'Hello Node!\n' - res.end(msg); + if (req.method === 'GET') { + // Fetch and display the contents of waardes.csv + https.get(azureStorageUrl, (response) => { + let data = ''; + response.on('data', (chunk) => { + data += chunk; + }); + + response.on('end', () => { + const lines = data.trim().split('\n'); + const values = lines.map((line) => { + const columns = line.split(';'); + return { + date: columns[0], + value: columns[1], + }; + }); + + res.statusCode = 200; + res.setHeader('Content-Type', 'text/html'); + res.write('
'); + + // Create a canvas for the chart + res.write(''); + + // Generate the chart using Chart.js + res.write(''); + res.write(''); + + res.write(''); + res.end(); + }); + }); + } }); server.listen(port, () => {