Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StaticWeb map static path can't include "index.html" ? #719

Closed
yunhor opened this issue Aug 12, 2017 · 8 comments
Closed

StaticWeb map static path can't include "index.html" ? #719

yunhor opened this issue Aug 12, 2017 · 8 comments

Comments

@yunhor
Copy link

yunhor commented Aug 12, 2017

Documentation for the iris project can be found at
https://github.com/kataras/iris#-learn.
iris version 8.2.4
When I use StaticWeb method map a static path, and request "static/index.html" ,it will "Not Found".
But when I change index.html to go.html ,it work .
I am sure the old iris hasn't this error .
2017-08-13 00-59-50

@kataras
Copy link
Owner

kataras commented Aug 12, 2017

Hello @yunhor

Could you please provide us a code-snippet that produces this type of result?

Update:

StaticWeb does not recognize http://localhost:8080/static/ as http://localhost:8080/static/index.html but this is not its fault, it's router's fault.

We have the app.SPA function which will do the job for you (derives from Single Page Application, was introduced in V8)

If you're serving the whole website from static assets (i.e view managed by react,angular...) use app.SPA instead, it's faster and is designed for that reason.

	assetHandler := app.StaticHandler("./static", false, false)
	app.SPA(assetHandler)

Examples can be found here: https://github.com/kataras/iris/tree/master/_examples/file-server/single-page-application

Update 2:

However I did some digging to a relative situation and I found a minor issue.

Update 3:

I found the origin of the (Update2) issue and I've fixed that but I have no time to test it much more right now, I'm in the office. I want to be 100% sure that we will not face an issue like that on the near future and I'll push the fix to the repository when I go back to my house. Wait for that fix, which solves the issue of StaticWeb you described on this thread.

Thank you,
Gerasimos Maropoulos

Please follow the project to learn about its new features, I am pushing a history entry on every single change, this way you will not have to post an issue every time.

@yunhor
Copy link
Author

yunhor commented Aug 12, 2017

2017-08-13 01-28-41

I map ./go to /go ,when ./go/go.htm change name to "index.html" ,It can't work on v8.2.4
":6300/go/index.html" neither

@yunhor
Copy link
Author

yunhor commented Aug 12, 2017

Thank you @kataras ,I will try SPA method.

@kataras
Copy link
Owner

kataras commented Aug 12, 2017

I found the origin of the issue and I've fixed that but I have no time to test it much more right now, I'm in the office. I want to be 100% sure that we will not face an issue like that on the near future and I'll push the fix to the repository when I go back to my house. Wait for that fix, which solves the issue of StaticWeb you described on this thread.

@kataras
Copy link
Owner

kataras commented Aug 12, 2017

Done, upgrade with go get -u github.com/kataras/iris and you're ready to go :)

@yunhor Thank you very much for your report, it lead me to fix an important issue we had in my mind for a long time.

Please star or watch the repository to receive real-time updates.

@jolee11
Copy link

jolee11 commented Nov 26, 2018

I just run iris-master/_examples/file-server/basic/main.go

All the following gives "Not Found"
http://localhost:8080/static
http://localhost:8080/static/
http://localhost:8080/static/index.html

If I rename index.html to i.html, then
http://localhost:8080/static/i.html gives "Hello index"

screen shot 2018-11-26 at 10 55 37 am

@kataras
Copy link
Owner

kataras commented Nov 28, 2018

@jolee11 this happens because /static/ redirects to /static and index.html is not part of the /static but /static/index.html. The /static/ or /static/index.html will redirect to /static and that was expected as go docs of the StaticWeb.

So you have two options,

  1. Register a handler for your /static to serve the index.html (this can give you control whether the user asked assets or a particular index page).
  2. to fix that you could pass iris.WithoutPathCorrection option to iris.Run(iris.Addr(...), iris.WithoutPathCorrection) however I will refactor the code a bit in order to fix this, stay tuned.

@jolee11
Copy link

jolee11 commented Nov 29, 2018

Thank you very much!

WingGao pushed a commit to WingGao/iris that referenced this issue Oct 9, 2020
… for good

Former-commit-id: 75b855bee9216c28ce8e1ff46aee467766c37f23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants