-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathvite.config.js
More file actions
65 lines (58 loc) · 1.94 KB
/
vite.config.js
File metadata and controls
65 lines (58 loc) · 1.94 KB
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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Custom Plugin for Uploads
const uploadPlugin = () => ({
name: 'configure-upload-server',
configureServer(server) {
console.log("--> [Plugin] Upload Plugin Registered");
server.middlewares.use('/upload', (req, res, next) => {
console.log(`--> [Plugin] Request to /upload: ${req.method}`);
if (req.method === 'POST') {
const chunks = [];
req.on('data', chunk => chunks.push(chunk));
req.on('end', () => {
try {
const buffer = Buffer.concat(chunks);
const uploadDir = resolve(__dirname, 'public/uploads');
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir, { recursive: true });
}
const fileName = `upload_${Date.now()}.webm`;
const filePath = path.join(uploadDir, fileName);
fs.writeFileSync(filePath, buffer);
console.log(`[Plugin] Saved upload: ${filePath}`);
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ url: `/uploads/${fileName}` }));
} catch (err) {
console.error('[Plugin] Upload error:', err);
res.statusCode = 500;
res.end(JSON.stringify({ error: err.message }));
}
});
} else {
next();
}
});
}
});
export default defineConfig({
plugins: [uploadPlugin()],
build: {
lib: {
entry: resolve(__dirname, 'src/VideoRecorder.js'),
name: 'VideoRecorderJS',
fileName: (format) => `videorecorder.${format}.js`,
},
rollupOptions: {
external: [],
output: {
globals: {},
},
},
}
});