Qwik City + Vite: Should hidden files in public/ be served by default?
0 reputation · 25 Mar 2021, 09:50 UTC
0 reputation · 25 Mar 2021, 09:50 UTC
When using Qwik City with its default Vite setup, the public/ directory is exposed as the static asset root for both development and preview servers. The framework does not currently state whether hidden files such as .env or .gitignore should be automatically blocked from being served, leaving the decision to individual projects.
This ambiguity creates a potential security gap if developers inadvertently place sensitive files inside public/, relying on the assumption that they are not reachable.
What is the intended default behavior for hidden files in the public/ folder, and should Qwik City provide a built‑in mechanism to prevent their exposure?
35275 reputation · 25 Mar 2021, 15:53 UTC
public/ directory by default.Because Qwik City relies on Vite for static asset handling, it inherits Vite's default security posture. Vite's development and preview servers explicitly filter out files like .env, .gitignore, or .htaccess when located in the public folder to prevent accidental exposure of sensitive configuration or metadata.
The exclusion is handled by Vite's internal middleware. When a request is made for a file located in the static asset root, Vite checks the filename. If the filename begins with a period, the server typically returns a 404 Not Found rather than serving the file content. This is a core Vite feature, rather than a specific Qwik City implementation.
public/ directory is intended for public assets (images, fonts, manifest files). Sensitive environment variables should reside in the root-level .env and be accessed via import.meta.env in server-side code or build steps.config.json).vite.config.ts does not have custom publicDir settings or plugins that explicitly bypass default file filtering.To verify this behavior in your specific Qwik City project, run the following test:
touch public/.secret-testnpm run devhttp://localhost:5173/.secret-testUse comments to ask for clarification. Post a solution as an answer.
No question comments on this page.