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

Add a default document names for the static method #3

Closed
hyingreborn opened this issue Jan 25, 2020 · 4 comments
Closed

Add a default document names for the static method #3

hyingreborn opened this issue Jan 25, 2020 · 4 comments

Comments

@hyingreborn
Copy link

Add a default document names for the static method plz : "index.html"、"index.htm"、"default.html"、"default.htm"

server.go

app.Static("./public/static", "/static")

when i visit http://127.0.0.1:8080/static,Instead of 404, the contents of index.html are displayed by default

@Fenny
Copy link
Member

Fenny commented Jan 25, 2020

Hi @hyingreborn ,

'index.html' files are added to the root path by default, I'm planning to disable this as an option in v1.1

By looking at your example you seem to use the function the wrong way and reversed the parameters, it should be Static(prefix, dir) or Static(dir).
https://gofiber.github.io/fiber/#/application?id=static

Change your code like this

app.Static("/static", "./public/static")

@Fenny Fenny closed this as completed Jan 25, 2020
@Fenny Fenny reopened this Jan 25, 2020
@Fenny Fenny closed this as completed Jan 26, 2020
@hyingreborn
Copy link
Author

@Fenny tks for your reply!
The static method is quite different from other frameworks,like gin or echo,The path rules for the files are not as expected,Can you refer to gin or echo?

@Fenny
Copy link
Member

Fenny commented Jan 28, 2020

Hi @hyingreborn ,
I checked out the static method details from the echo documention and it's almost identical.
https://echo.labstack.com/guide/static-files

The only difference with the static method from fiber is that the virtual path prefix is optional. If you don't use a prefix, it defaults to /.

The following examples achieve the same results:

app := fiber.New()
app.Static("/", "./my/static/files")
// => http://localhost:8080/gopher.png

app.Static("./my/static/files")
// => http://localhost:8080/gopher.png

@hyingreborn
Copy link
Author

hyingreborn commented Jan 29, 2020

Hi @Fenny
I built a SPA using Vuejs,then try to add it to Fiber's project,directory structure like this:

|-public
|--favicon.ico // for global path to visit
|--app // VueJS's SPA
|---index.html
|---favicon.ico // for spa path to visit
|---js
|---css
|---...
|-go.mod
|-main.go

I hope that through http://127.0.0.1:8080/app to access the directory/public/app, so I this configuration:

app := fiber.New()
app.Static("/app", "./public/app")

The result is that i can only access index.html as the default document, and no other static files are not accessible,my vue's spa already config public path to "./",It works in subdirectories under both gin and echo。

The expectation should be to map app/* to./public/app/*

app.Static("/app/*", "./public/app/*")

By the way, /app doesn't automatically add the "/" suffix

Fenny pushed a commit that referenced this issue Feb 7, 2020
Commit from Fiber master
Fenny pushed a commit that referenced this issue Feb 16, 2020
Accumulative update @ 16 Feb 2020
koddr added a commit that referenced this issue Mar 7, 2020
Accumulative update @ 07 Mar 2020
Fenny pushed a commit that referenced this issue Oct 26, 2020
kiyonlin pushed a commit that referenced this issue Dec 28, 2020
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

2 participants