-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.dev.config.ts
More file actions
47 lines (45 loc) · 1.3 KB
/
vite.dev.config.ts
File metadata and controls
47 lines (45 loc) · 1.3 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { readFileSync, existsSync } from 'fs';
function serveSamples() {
const samplesDir = resolve(__dirname, 'samples');
const mimeTypes: Record<string, string> = {
'.epub': 'application/epub+zip',
'.pdf': 'application/pdf',
'.cbz': 'application/vnd.comicbook+zip',
};
return {
name: 'serve-samples',
configureServer(server: any) {
server.middlewares.use('/samples', (req: any, res: any, next: any) => {
// Strip query parameters from URL
const urlPath = req.url.split('?')[0].slice(1);
const filePath = resolve(samplesDir, urlPath);
if (existsSync(filePath)) {
// Set correct content type based on extension
const ext = urlPath.substring(urlPath.lastIndexOf('.'));
const contentType = mimeTypes[ext] || 'application/octet-stream';
res.setHeader('Content-Type', contentType);
res.end(readFileSync(filePath));
} else {
next();
}
});
},
};
}
export default defineConfig({
root: 'demo',
server: {
fs: {
allow: ['..'],
},
},
plugins: [serveSamples()],
resolve: {
alias: {
'speed-read': resolve(__dirname, 'src/index.ts'),
'@': resolve(__dirname, 'src'),
},
},
});