Nuxt.js module to use Unleash toggle feature services
Use $unleash
to access and handle your Unleash feature flags in client side,
or context.app.unleash
to access Unleash feature flags from server side.
- Add
nuxt-unleash
dependency to your project
yarn add nuxt-unleash
- Add
nuxt-unleash
to themodules
section ofnuxt.config.js
export default {
modules: [
// Simple usage
'nuxt-unleash',
// With options
['nuxt-unleash', { /* module options */ }]
]
}
dependency
(No --dev
or --save-dev
flags) and use modules
section in nuxt.config.js
instead of buildModules
.
export default {
buildModules: [
'nuxt-unleash'
],
unleash: {
/* module options */
}
}
- Type:
String
- Required:
true
Unleash API URL
- Type:
String
- Required:
true
Unleash API Instance ID
- Type:
String
- Required:
false
Name of the environment your Unleash application runs in. See the example configuration.
The module allows some configuration parameters.
If you want to default to the value of a feature that doesn't exist, use:
enabledDefault: true
On the other hand, to set a header as the source of the ip, you can add:
headerIP: 'CF-Connection-IP'
To access the module in side client you just have to call this.$unleash
and method you want to use.
<template>
<h1>{{ value ? 'enabled' : 'disabled' }}</h1>
</template>
<script>
export default {
mounted() {
this.value = this.$unleash.isEnabled('new-feature')
}
}
</script>
To access the module in side server you just have to call ctx.app.unleash
and method you want to use.
asyncData(ctx) {
const value = ctx.app.unleash.isEnabled('new-feature')
if(value) {
ctx.redirect('/new-feature-page')
}
}
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Start development server using
npm run dev
Copyright (c) Conejerock