mirror of https://github.com/gofiber/fiber.git
Fix typo
parent
2730e0c2ff
commit
fe35768f4e
|
@ -121,6 +121,42 @@ app.All(...)
|
||||||
app.Use(...)
|
app.Use(...)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Static
|
||||||
|
To serve static files such as images, CSS files, and JavaScript files, replace your function handler with a file or directory string.
|
||||||
|
```go
|
||||||
|
// Function signature
|
||||||
|
app.Static(root string)
|
||||||
|
app.Static(prefix, root string)
|
||||||
|
```
|
||||||
|
For example, use the following code to serve images, CSS files, and JavaScript files in a directory named public:
|
||||||
|
|
||||||
|
```go
|
||||||
|
app.Static("./public")
|
||||||
|
```
|
||||||
|
Now, you can load the files that are in the public directory:
|
||||||
|
```shell
|
||||||
|
http://localhost:8080/hello.html
|
||||||
|
http://localhost:8080/js/jquery.js
|
||||||
|
http://localhost:8080/css/style.css
|
||||||
|
```
|
||||||
|
To use multiple static assets directories, call the Static function multiple times:
|
||||||
|
```go
|
||||||
|
app.Static("./public")
|
||||||
|
app.Static("./files")
|
||||||
|
```
|
||||||
|
?>For best results, use a reverse proxy cache like [NGINX](https://www.nginx.com/resources/wiki/start/topics/examples/reverseproxycachingexample/) to improve performance of serving static assets.
|
||||||
|
|
||||||
|
To create a virtual path prefix (where the path does not actually exist in the file system) for files that are served by the express.static function, specify a mount path for the static directory, as shown below:
|
||||||
|
```go
|
||||||
|
app.Static("/static", "./public")
|
||||||
|
```
|
||||||
|
Now, you can load the files that are in the public directory from the /static path prefix.
|
||||||
|
```shell
|
||||||
|
http://localhost:8080/static/hello.html
|
||||||
|
http://localhost:8080/static/js/jquery.js
|
||||||
|
http://localhost:8080/static/css/style.css
|
||||||
|
```
|
||||||
|
|
||||||
#### Listen
|
#### Listen
|
||||||
Binds and listens for connections on the specified address. This can be a **INT** for port or **STRING** for address. To enable **TLS/HTTPS** you can append your **cert** and **key** path.
|
Binds and listens for connections on the specified address. This can be a **INT** for port or **STRING** for address. To enable **TLS/HTTPS** you can append your **cert** and **key** path.
|
||||||
```go
|
```go
|
||||||
|
|
|
@ -836,7 +836,7 @@ app.Get("/not-found", func(c *fiber.Ctx) {
|
||||||
```
|
```
|
||||||
|
|
||||||
#### SendStatus
|
#### SendStatus
|
||||||
Sets the status code, but also the correct status message in the body if the response body is still empty.
|
Sets the status code, but also the correct status message in the body if the response body is still empty. You can find all status codes and messages in [status.go](https://github.com/gofiber/fiber/blob/master/status.go)
|
||||||
```go
|
```go
|
||||||
// Function signature
|
// Function signature
|
||||||
c.SendStatus(status int)
|
c.SendStatus(status int)
|
||||||
|
|
|
@ -29,9 +29,11 @@ import "github.com/gofiber/fiber"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
|
||||||
app.Get("/", func(c *fiber.Ctx) {
|
app.Get("/", func(c *fiber.Ctx) {
|
||||||
c.Send("Hello, World!")
|
c.Send("Hello, World!")
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Listen(8080)
|
app.Listen(8080)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -106,30 +108,9 @@ app.Static("./public")
|
||||||
```
|
```
|
||||||
Now, you can load the files that are in the public directory:
|
Now, you can load the files that are in the public directory:
|
||||||
```shell
|
```shell
|
||||||
http://localhost:8080/images/kitten.jpg
|
|
||||||
http://localhost:8080/css/style.css
|
|
||||||
http://localhost:8080/js/app.js
|
|
||||||
http://localhost:8080/images/bg.png
|
|
||||||
http://localhost:8080/hello.html
|
http://localhost:8080/hello.html
|
||||||
```
|
http://localhost:8080/js/jquery.js
|
||||||
To use multiple static assets directories, call the Static function multiple times:
|
http://localhost:8080/css/style.css
|
||||||
```go
|
|
||||||
app.Static("./public")
|
|
||||||
app.Static("./files")
|
|
||||||
```
|
|
||||||
?>For best results, use a reverse proxy cache like [NGINX](https://www.nginx.com/resources/wiki/start/topics/examples/reverseproxycachingexample/) to improve performance of serving static assets.
|
|
||||||
|
|
||||||
To create a virtual path prefix (where the path does not actually exist in the file system) for files that are served by the express.static function, specify a mount path for the static directory, as shown below:
|
|
||||||
```go
|
|
||||||
app.Static("/static", "./public")
|
|
||||||
```
|
|
||||||
Now, you can load the files that are in the public directory from the /static path prefix.
|
|
||||||
```shell
|
|
||||||
http://localhost:8080/static/images/kitten.jpg
|
|
||||||
http://localhost:8080/static/css/style.css
|
|
||||||
http://localhost:8080/static/js/app.js
|
|
||||||
http://localhost:8080/static/images/bg.png
|
|
||||||
http://localhost:8080/static/hello.html
|
|
||||||
```
|
```
|
||||||
|
|
||||||
*Caught a mistake? [Edit this page on GitHub!](https://github.com/gofiber/fiber/blob/master/docs/getting_started.md)*
|
*Caught a mistake? [Edit this page on GitHub!](https://github.com/gofiber/fiber/blob/master/docs/getting_started.md)*
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Static ...
|
// Static https://gofiber.github.io/fiber/#/application?id=static
|
||||||
func (r *Fiber) Static(args ...string) {
|
func (r *Fiber) Static(args ...string) {
|
||||||
prefix := "/"
|
prefix := "/"
|
||||||
root := "./"
|
root := "./"
|
||||||
|
|
|
@ -10,6 +10,7 @@ package fiber
|
||||||
// Credits @valyala
|
// Credits @valyala
|
||||||
// https://github.com/valyala/fasthttp/blob/master/status.go
|
// https://github.com/valyala/fasthttp/blob/master/status.go
|
||||||
|
|
||||||
|
// statusMessages https://gofiber.github.io/fiber/#/context?id=sendstatus
|
||||||
var statusMessages = map[int]string{
|
var statusMessages = map[int]string{
|
||||||
100: "Continue",
|
100: "Continue",
|
||||||
101: "Switching Protocols",
|
101: "Switching Protocols",
|
||||||
|
|
Loading…
Reference in New Issue