N
Nuxt3d ago
cosbgn

Does anyone knows how to set CORS for static files (/public)?

I know with nitro, but I'm talking about files in the public folder. I tried with routeRules but they don't seem to apply to static files.
2 Replies
kapa.ai
kapa.ai3d ago
Hi @cosbgn. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources provided, there isn't specific information about setting CORS for static files in the /public folder of a Nuxt application. However, I can provide some relevant information and suggestions: 1. The routeRules configuration in Nuxt is primarily designed for dynamic routes and may not directly apply to static files in the public folder. This is mentioned in your question and aligns with the information available. 2. For general CORS configuration, Nuxt uses Nitro, which provides CORS utilities. However, these are typically applied to API routes or dynamic content, not static files. H3 Utils Documentation mentions CORS-related functions, but they are not specifically for static files. 3. A potential workaround could be to configure CORS at the server level, rather than within the Nuxt application. This would depend on your hosting environment. 4. If you're using a reverse proxy like Nginx, you might be able to add CORS headers for specific locations. An example of Nginx configuration is provided in this Stack Overflow post, but it doesn't specifically address CORS for static files. Given the limitations of the information available in the knowledge sources, I cannot provide a definitive solution for setting CORS specifically for static files in the /public folder of a Nuxt application. You might need to explore server-level configurations or consult Nuxt's official documentation for any updates on this specific use case. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3d ago
<@335585860764303360> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?