Hi, I have recently upgraded to v12.0.1 and started experiencing the issue that static files are not getting served properly. My scenario is like this:
```
$ tree
βββ assets
β βββ static
β βββ css
β βββ js
βββ go.mod
βββ go.sum
βββ internal
β βββ templates
β βββ templates.go <- This here is generated as an out of running go-bindata
βββ main.go
βββ pkg
βββ runner
βββ runner.go
- They are converted to their "bin" format using `go-bindata` but with custom `pkg` name and `output` dir.
When I try to access the static files, I get 404.
I am attaching a very simple project to replicate the issue.
[iris-static-issue.zip](https://github.com/kataras/iris/files/3801808/iris-static-issue.zip)
Steps:
// Inside the project
$ go get -u github.com/go-bindata/go-bindata/...
$ go-bindata -o internal/templates/templates.go -pkg templates assets/...
$ go build .
$ ./iris-static-issue
// Now try to query the end points
curl -i http://localhost:8080/static/js/jquery-2.1.1.js <- Fails with 404
curl -i http://localhost:8080/static/css/bootstrap.min.css <- Fails with 404
```
Templates are embedded using the 'view.Binary' method, static files through 'app.HandleDir'. I will check your code as soon as I come back to my town office but I dont think there is an issue with embedded files because they are working properly in our servers. We'll talk later on if you still have the issue.
Thank you for your response.
Sure, it was a naming mistake in the same project, I named it as "templates" rather than "static".
But the problem still persists.
I can also confirm that the pattern I have described in above zip file works very well in fairly large project with version v11.2.8. But I started encountering this when I attempted to migrate it to v12.x.x
Hello @ansrivas, you are very welcome. I thank you for using Iris for so long time!
It shouldn't work on v11.2.8, the only change on static file serving was at: https://github.com/kataras/iris/issues/1383. I think you are mistaken - actually the problem is that you serve http://localhost:8080/static/static/css/bootstrap.min.css but you really wanted the http://localhost:8080/static/css/bootstrap.min.css.
See your internal/templates/templates.go file:
// Code generated by go-bindata. DO NOT EDIT.
// sources:
// assets/static/css/bootstrap.min.css
// assets/static/js/jquery-2.1.1.js
^ Here ./assets/static -> /static request path will serve ./assets, so your code will serve /static/static/$resource based on the zip file you sent above.
_More:_ Based on the templates.go, when you do app.HandleDir("/static", "./assets", ..) it will serve /static/ as ./assets/... but your ./assets bindata does not contain any file, it has only one folder, the /static one which contains the static files(/assets/static/bootstrap.min.css) you want to serve.
Solution
You need to run go-bindata from the static directory itself cd assets && go-bindata -o ../internal/templates/templates.go -pkg templates ./static/... then the internal/templates/templates.go will start with the correct folder /static/... (it's a go-bindata thing not an Iris one, this behavior is expected as AssetInfo and _bindata variable inside templates.go can't locate the file otherwise):
// Code generated by go-bindata. DO NOT EDIT.
// sources:
// static\css\bootstrap.min.css
// static\js\jquery-2.1.1.js
The below is working (see the terminal panel),

Iris ties to* locate and validate the embedded assets based on the 'virtual directory' given by the second parameter of app.HandleDir/iris.FileServer, we have the iris.StripPrefix too.
@kataras thank you for this detailed explanation.
Indeed your suggested solution worked perfectly :)
Glad to help @ansrivas!