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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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 viahttp://yourserver/asset/project_1/css/style.css
. Similarly, a file atassets/project_1/vendor/aos/bootstrap/file.css
should be accessible athttp://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:
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