diff --git a/docs/application.md b/docs/application.md index 2787beac..c004f38e 100644 --- a/docs/application.md +++ b/docs/application.md @@ -121,6 +121,42 @@ app.All(...) 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 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 diff --git a/docs/context.md b/docs/context.md index 2a431656..0a30db0a 100644 --- a/docs/context.md +++ b/docs/context.md @@ -836,7 +836,7 @@ app.Get("/not-found", func(c *fiber.Ctx) { ``` #### 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 // Function signature c.SendStatus(status int) diff --git a/docs/getting_started.md b/docs/getting_started.md index dc930db8..4277475c 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -29,9 +29,11 @@ import "github.com/gofiber/fiber" func main() { app := fiber.New() + app.Get("/", func(c *fiber.Ctx) { c.Send("Hello, World!") }) + app.Listen(8080) } ``` @@ -106,30 +108,9 @@ app.Static("./public") ``` Now, you can load the files that are in the public directory: ```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 -``` -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/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 +http://localhost:8080/js/jquery.js +http://localhost:8080/css/style.css ``` *Caught a mistake? [Edit this page on GitHub!](https://github.com/gofiber/fiber/blob/master/docs/getting_started.md)* diff --git a/static.go b/static.go index 58b3939b..ba83dcc3 100644 --- a/static.go +++ b/static.go @@ -12,7 +12,7 @@ import ( "strings" ) -// Static ... +// Static https://gofiber.github.io/fiber/#/application?id=static func (r *Fiber) Static(args ...string) { prefix := "/" root := "./" diff --git a/status.go b/status.go index ef3de01f..2f1dd35f 100644 --- a/status.go +++ b/status.go @@ -10,6 +10,7 @@ package fiber // Credits @valyala // https://github.com/valyala/fasthttp/blob/master/status.go +// statusMessages https://gofiber.github.io/fiber/#/context?id=sendstatus var statusMessages = map[int]string{ 100: "Continue", 101: "Switching Protocols",