-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
85 lines (82 loc) · 2.72 KB
/
Copy pathvite.config.js
File metadata and controls
85 lines (82 loc) · 2.72 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { createReadStream, existsSync, statSync } from 'fs'
import { join, extname, dirname, normalize, sep } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const DATA_DIR = join(__dirname, 'data', 'Release_1', 'Release_1')
const DATA_ROOT = join(__dirname, 'data')
const MIME_MAP = {
'.pdf': 'application/pdf',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.mp4': 'video/mp4',
'.webm': 'video/webm',
'.mov': 'video/quicktime',
}
function serveDataPlugin() {
return {
name: 'serve-data-files',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const url = (req.url || '').split('?')[0]
if (!url.startsWith('/data/')) return next()
try {
const filename = decodeURIComponent(url.slice(6))
if (!filename) return next()
const filepath = filename.includes('/')
? join(DATA_ROOT, filename)
: join(DATA_DIR, filename)
const normalized = normalize(filepath)
const allowedRoots = [
DATA_DIR,
join(DATA_ROOT, 'release_02_document_bundle'),
join(DATA_ROOT, 'release_03_documents'),
join(DATA_ROOT, 'uap052226'),
join(DATA_ROOT, 'uap_videos_061226'),
].map(root => normalize(root) + sep)
if (!allowedRoots.some(root => normalized.startsWith(root))) return next()
if (!existsSync(filepath)) return next()
const stat = statSync(filepath)
if (!stat.isFile()) return next()
const mime = MIME_MAP[extname(filepath).toLowerCase()] || 'application/octet-stream'
res.setHeader('Content-Type', mime)
res.setHeader('Content-Length', stat.size)
res.setHeader('Content-Disposition', 'inline')
res.setHeader('Cache-Control', 'public, max-age=3600')
createReadStream(filepath).pipe(res)
} catch { next() }
})
}
}
}
export default defineConfig({
plugins: [react(), tailwindcss(), serveDataPlugin()],
optimizeDeps: {
include: ['leaflet'],
},
server: {
proxy: {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true,
}
}
},
build: {
chunkSizeWarningLimit: 1500,
rollupOptions: {
output: {
manualChunks: {
'three': ['three', '@react-three/fiber', '@react-three/drei'],
'd3': ['d3'],
'framer': ['framer-motion'],
'react': ['react', 'react-dom'],
'leaflet': ['leaflet', 'react-leaflet'],
}
}
}
}
})