I have a gin application in which not all the static files load. Deeply rooted static files do not load.
### **Static file path**
## repository
assets
project_1
css/style.css
vendor/aos/bootstrap
Files in the **aos ** folder do not load, but files in the **css ** folder load. I have tried router.Static(“/asset”, “./repository/assets”) but it does not work.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
The issue you’re facing with Gin where some deeply nested static files are not loading while others are could be related to how the static file serving is set up. When you use router.Static("/asset", "./repository/assets"), it should theoretically serve all files under the ./repository/assets directory accessible via the /asset endpoint. However, there might be nuances affecting the accessibility of files in deeper nested directories.
You need to verify the URL you’re using to access the files. For instance, the file at assets/project_1/css/style.css should be accessed via http://yourserver/asset/project_1/css/style.css. Similarly, a file at assets/project_1/vendor/aos/bootstrap/file.css should be accessible at http://yourserver/asset/project_1/vendor/aos/bootstrap/file.css.
Also, check that the server has the necessary permissions to read the files in the aos and other nested directories.
If the above steps are correct, consider testing with a more explicit static file serving setup for the problematic directory to see if it resolves the issue:
router := gin.Default()
router.Static("/asset", "./repository/assets")
// Explicitly define the path for nested directories if needed
router.Static("/asset/project_1/vendor/aos", "./repository/assets/project_1/vendor/aos")
router.Run(":8080")
Along with the above add logging to your application to check whether the requests for the static files are hitting the server and how they’re being resolved. It might provide insights into why certain files aren’t being served.
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.