diff --git a/express/server.js b/express/server.js index ad05e84..bad8365 100644 --- a/express/server.js +++ b/express/server.js @@ -108,30 +108,17 @@ router.post('/api', async (req, res) => { let nume = req.body.nume if(!nume) nume = 'list'; + let bom = "\ufeff" let csvcontent = await csv.toString(); - fs.writeFile('./csv/' + nume + '.csv', "\ufeff" + csvcontent, (err) => { - if (err) - throw err; - console.log("The file was succesfully saved with UTF-8 with BOM!"); - res.download('./csv/' + nume + '.csv', nume + '.csv', function (err) { - fs.unlink('./csv/' + nume + '.csv', function () { - console.log("Deleted: " + nume); - }); - }); - - }) - + csvcontent = bom.concat(csvcontent) + res.set({'Content-Disposition': 'attachment; filename='+nume+'.csv','Content-type': 'text/csv'}); + res.send(csvcontent); // csv.toDisk('./csv/'+nume+'.csv', {append: false, bom: true}) test = []; ok = 2; // await res.send('It works') // parse(`Hello \nworld sd`) }) - router.get('/', (req, res) => { - res.writeHead(200, { 'Content-Type': 'text/html' }); - res.write('

Hello from Express.js!

'); - res.end(); -}); app.use(express.static(__dirname + '/public')); app.use('/.netlify/functions/server', router); // path must route to lambda app.use('/', (req, res) => res.sendFile(path.join(__dirname, '../index.html'))); diff --git a/index.html b/index.html deleted file mode 100644 index a8d5678..0000000 --- a/index.html +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/public/index.html b/public/index.html index c1c512d..fe0c272 100644 --- a/public/index.html +++ b/public/index.html @@ -9,7 +9,7 @@
-
+ @@ -17,4 +17,4 @@
- \ No newline at end of file +