Description

I am trying import my static file with Static() function, but it seem gin can not find the file. How can I fix this?

How to reproduce

In router

router.Static("/static", "/view")
router.LoadHTMLGlob("view/html/**/*")

local path

├── main.go
└── view
      ├── css
      │     └── style.css
      ├── html
      │     ├── component
      │     └── meta
      │           └── index.html
      └── js
             └── render.js

HTML import

<link rel="stylesheet" href="/static/css/style.css" >

and my console in debug mode show that handlers has generate

[GIN-debug] GET    /static/*filepath         --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] HEAD   /static/*filepath         --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)

Expectations

rend css file correctly

Actual result

404 response of the css file

my custom log

2020-07-01T07:05:15.747+0800    INFO    /static/123.js  {"status": 404, "method": "GET"}

Environment

  • go version: go1.13.4 linux/amd64
  • gin version (or commit ref): v1.5.0
  • operating system: Ubuntu 18.04.4 LTS (Bionic Beaver)

Comment From: cp-sumi-k

@Yan-Bin-Lin Use ./view instead of /view in router.static method

Comment From: PaperPrototype

I am having the same issue!

Comment From: PaperPrototype

And... @Yan-Bin-Lin there is no folder called "static" so that might be your issue! 😊

Comment From: bytedaring

[cid:901FBCC3-5B8A-4AE0-A040-3233EECFFFEC]

2021年10月25日 10:28,Abdiel Lopez @.**@.**>> 写道:

I am having the same issue!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/gin-gonic/gin/issues/2420#issuecomment-950471908, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABCMDT6FPCDELUAKYJ43VPDUIS6DLANCNFSM4OM3NSCA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Comment From: CCathlete

This issue have probably already been closed, but it might help others who are facing this issue. the format of path you need to put inside should look like this: // For css. router.Static("/view/css", "./view/css") // For js. router.Static("/view/js", "./view/js")

There might be a more elegant way of doing this but I don't understand anything about filesystems so that's how I solved it.