Skip to content

A Netlify plugin to dynamically replace environment variables defined in _redirects file

Notifications You must be signed in to change notification settings

ebsaral/netlify-plugin-redirect-env-placeholders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

netlify-plugin-redirect-env-placeholders

This plugin replaces the placeholders defined in _redirects file dynamically on preBuild stage.

What it does

Imagine you have a file for your redirects defined in _redirects file:

/api/checkout/* {{env:TEST_API_URL}}/:splat 200

/api/auth/* {{env:ENV_NON_EXISTENT|http://default-domain.com}}/api/auth/:splat 200

And you defined TEST_API_URL environment variable to be https://this.is.test/hey

With this plugin, your published _redirects will be transformed to:

/api/checkout/* https://this.is.test/hey/:splat 200

/api/auth/* http://default-domain.com/api/auth/:splat 200

How to use

Syntax

{{env:ENV_VAR_NAME}} or {{env:ENV_VAR_NAME|default_value}} (if the variable does not exist, default_value will be written)

netlify.toml

[[plugins]]
package = "netlify-plugin-redirect-env-placeholders"
  [plugins.inputs]
  source = '_redirects'
  base = '/opt/build/repo/'

Both inputs are optional:

name description default
source Source filename (It should be on the root path of your project) _redirects
base Base path of the build during preBuild step where files exist .

Note

If you would like to use this plugin with netlify-plugin-contextual-env, please make sure that this plugin is added afterwards.

About

A Netlify plugin to dynamically replace environment variables defined in _redirects file

Resources

Stars

Watchers

Forks

Packages

No packages published