Files
hnh-map/frontend-nuxt/plugins/vite-uri-guard.ts
Nikolay Tatarinov 605a31567e Add initial project structure with backend and frontend setup
- Created backend structure with Go, including main application logic and API endpoints.
- Added Docker support for both development and production environments.
- Introduced frontend using Nuxt 3 with Tailwind CSS for styling.
- Included configuration files for Docker and environment variables.
- Established basic documentation for contributing, development, and deployment processes.
- Set up .gitignore and .dockerignore files to manage ignored files in the repository.
2026-02-24 22:27:05 +03:00

32 lines
1.0 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: any, res: any, 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 })
},
}
}