- Introduced .editorconfig for consistent coding styles across the project. - Added .golangci.yml for Go linting configuration. - Updated AGENTS.md to clarify project structure and components. - Enhanced CONTRIBUTING.md with Makefile usage for common tasks. - Updated Dockerfiles to use Go 1.24 and improved build instructions. - Refined README.md and deployment documentation for clarity. - Added testing documentation in testing.md for backend and frontend tests. - Introduced Makefile for streamlined development commands and tasks.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import type { Plugin } from 'vite'
|
|
|
|
/**
|
|
* Dev-only: reject requests with malformed URIs before Vite's static/transform
|
|
* middleware runs decodeURI(), which would throw and crash the server.
|
|
* See: https://github.com/vitejs/vite/issues/6482
|
|
*/
|
|
export function viteUriGuard(): Plugin {
|
|
return {
|
|
name: 'vite-uri-guard',
|
|
apply: 'serve',
|
|
configureServer(server) {
|
|
const guard = (req: { url?: string; originalUrl?: string }, res: { statusCode: number; setHeader: (k: string, v: string) => void; end: (body: string) => void }, next: () => void) => {
|
|
const raw = req.url ?? req.originalUrl ?? ''
|
|
try {
|
|
decodeURI(raw)
|
|
const path = raw.includes('?') ? raw.slice(0, raw.indexOf('?')) : raw
|
|
if (path) decodeURI(path)
|
|
} catch {
|
|
res.statusCode = 400
|
|
res.setHeader('Content-Type', 'text/plain')
|
|
res.end('Bad Request: malformed URI')
|
|
return
|
|
}
|
|
next()
|
|
}
|
|
// Prepend so we run before Vite's static/transform middleware (which calls decodeURI)
|
|
server.middlewares.stack.unshift({ route: '', handle: guard })
|
|
},
|
|
}
|
|
}
|