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

StaticMiddleware(path) precedence #56

Closed
qknight opened this issue Dec 5, 2015 · 7 comments
Closed

StaticMiddleware(path) precedence #56

qknight opened this issue Dec 5, 2015 · 7 comments

Comments

@qknight
Copy link

qknight commented Dec 5, 2015

Using this code:

  path, _ := os.Getwd()
  path += "/public/media"
  router := web.New(Context{}).

  Middleware(web.LoggerMiddleware).           // Use some included middleware
  Middleware(web.ShowErrorsMiddleware).
  Middleware(web.StaticMiddleware(path)).
  Get("/index.html", (*Context).Main).
  Get("/", (*Context).Main).
  NotFound((*Context).NotFound)

One can not just open: localhost:3000 in the browser because one is then always matched against the StaticMiddleware. But I would like that localhost:3000 opens the Main page instead of having to type, say localhost:3000/index.html every time.

Am I missing something here?

@PatrickWolleb
Copy link

I would use a front end proxy (something like Nginx, HAroxy) to do static file serving instead. If you are looking for a more feature-rich framework you should have a go at Beego or Revel.

Suggest close.

@qknight
Copy link
Author

qknight commented Dec 7, 2015

my point is:
http://localhost:3000 will redirect me to 'page not found' when i enable Middleware(web.StaticMiddleware(path)) which should not be the case as i have a Get("/", (*Context).Main).

i just don't want to type:
localhost:3000/index.html every time.

for development it would be great to have GO serving all files. later it would, as you advice, a good idea to use a reverse proxy for that purpose.

thanks for your help so far but i think that either i'm using the gocraft/web wrongly or there is a bug in the StaticMiddleware

@hydrogen18
Copy link

@qknight Instead of using a middleware to serve your static files for development purposes, couldn't you write an implementation of http.Handler that does that? Then you could put it at the end of the calls to router.Get. From what I understand it's an ordered list, i.e. first match wins.

@qknight
Copy link
Author

qknight commented Dec 16, 2015

yes, i could write my own code but isn't StaticMiddleware for that?

@hydrogen18
Copy link

Are you actually saying that doing GET localhost:3000 returns a status code of 302 with a redirect to a non existent page? The StaticMiddleware just calls http.ServeContent if the file exists, so I'm not sure how this would be happening.

@qknight
Copy link
Author

qknight commented Dec 16, 2015

GET localhost:3000 actually returns (on chromium):

ERR_CONTENT_LENGTH_MISMATCH

using curl i see this:

curl localhost:3000/
curl: (18) transfer closed with 9223372036854775807 bytes remaining to read

curl localhost:3000/index.html
<html><h1>index</h1><p>welcome to index.html!</p></html>

curl localhost:3000/asdf
<html><h1>404</h1><p>404: Element not found!</p></html>%                                              

@qknight
Copy link
Author

qknight commented Dec 16, 2015

according to:
brunoksato@37aedfa

i was doing it wrong!

Middleware(web.StaticMiddleware(path))

was changed to:

Middleware(web.StaticMiddleware(path, web.StaticOption{Prefix: "/public"})).

which makes 'http://localhost:3000' work!

thanks everyone

@qknight qknight closed this as completed Dec 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants