-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (58 loc) · 1.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
MSync
SWR EXPERIMENTALSTUDIO
Maurice Oeser
2023
Davor Vincze - FLUCHT
Smartphone Soundfile Controler
ermöglicht es Soundfiles synchron auf den Handys des Publikums abzuspielen und zu steuern
*/
// **************** Server setup ****************************
const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express();
const https = require('https');
const http = require('http');
const httpServer = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(httpServer);
app.use(express.raw({ type: '*/*', limit: '10mb' }));
app.use(express.static('public'));
// app.use(express.static(path.join(__dirname, 'public'), {
// setHeaders: (res, filePath) => {
// if (filePath.endsWith('.mp4')) {
// // Set Cache-Control header for MP4 videos
// res.set('Cache-Control', 'public, max-age=7200000');
// }
// }
// }));
app.get('/', (req, res) => {
console.log(req);
let data = "heureka";
res.send(data);
});
app.post("/test", (req,res) => {
console.log(req.query.project);
console.log('testfile.xml', req.body);
// Decode the Base64 string to a binary buffer
const fileBuffer = Buffer.from(req.body, 'base64');
// Define the file path where you want to save the file
const filePath = path.join(__dirname, '/public/projects/uploaded_file.xml');
// Write the file buffer to a file
fs.writeFile(filePath, req.body, (err) => {
if (err) {
console.error('Failed to save the file:', err);
} else {
console.log('File saved successfully.');
}
});
res.send("file uploaded");
});
app.get("/test2", (req, res) => {
res.sendFile(__dirname + '/public/projects/uploaded_file.xml');
});
httpServer.listen(8080, () => {
console.log('Server running on port 8080');
});
// ==========================================================