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 envvar middleware docs #276

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [CORS](api/middleware/cors.md)
* [CSRF](api/middleware/csrf.md)
* [Encrypt Cookie](api/middleware/encryptcookie.md)
* [EnvVar](api/middleware/envvar.md)
* [ETag](api/middleware/etag.md)
* [Expvar](api/middleware/expvar.md)
* [Favicon](api/middleware/favicon.md)
Expand Down
1 change: 1 addition & 0 deletions api/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ description: >-
* **gofiber/basicauth** Basic auth middleware provides an HTTP basic authentication. It calls the next handler for valid credentials and 401 Unauthorized for missing or invalid credentials.
* **gofiber/cors** Enable cross-origin resource sharing \(CORS\) with various options.
* **gofiber/csrf** Protect from CSRF exploits.
* **gofiber/envvar** This middleware enables to expose environment variables.
* **gofiber/helmet** Helps secure your apps by setting various HTTP headers.
* **gofiber/jwt** JWT returns a JSON Web Token \(JWT\) auth middleware.
* **gofiber/keyauth** Key auth middleware provides a key-based authentication.
Expand Down
81 changes: 81 additions & 0 deletions api/middleware/envvar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Exposing Environment Variables Middleware

EnvVar middleware for [Fiber](https://github.com/gofiber/fiber) that can be used to expose environment variables with various options.

## Table of Contents

* [Signatures](envvar.md#signatures)
* [Examples](envvar.md#examples)
* [Default Config](envvar.md#default-config)
* [Custom Config](envvar.md#custom-config)
* [Response](envvar.md#response)
* [Config](envvar.md#config)
* [Default Config](envvar.md#default-config-1)

## Signatures

```go
func New(config ...Config) fiber.Handler
```

## Examples

First import the middleware from Fiber,

```go
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/envvar"
)
```

Then create a Fiber app with `app := fiber.New()`.

**Note**: You need to provide a path to use envvar middleware.

### Default Config

```go
app.Use("/expose/envvars", envvar.New())
```

### Custom Config

```go
app.Use("/expose/envvars", envvar.New(envvar.Config{
ExportVars: map[string]string{"testKey": "", "testDefaultKey": "testDefaultVal"},
ExcludeVars: map[string]string{"excludeKey": ""}}
}))
```

### Response

Http response contract:
```
{
"vars": {
"someEnvVariable": "someValue",
"anotherEnvVariable": "anotherValue",
}
}

```

## Config

```go
// Config defines the config for middleware.
type Config struct {
// ExportVars specifies the environment variables that should export
ExportVars map[string]string
// ExcludeVars specifies the environment variables that should not export
ExcludeVars map[string]string
}

```

## Default Config

```go
Config{}
```