Skip to content

Commit

Permalink
Merge pull request #276 from mstrYoda/master
Browse files Browse the repository at this point in the history
add envvar middleware docs
  • Loading branch information
ReneWerner87 committed Aug 30, 2022
2 parents 03c949f + 6955aa0 commit cdd5598
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
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{}
```

0 comments on commit cdd5598

Please sign in to comment.