Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ name: Continuous Integration

on: [push]

permissions:
contents: read

jobs:
continuous-integration:
name: Continuous Integration
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7

- uses: actions/setup-node@v4
- uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
cache: npm

- name: Install dependencies
run: npm ci
Expand Down
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
24
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
# featurevisor-example-nuxt

Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
Example of using the [Featurevisor JavaScript SDK](https://featurevisor.com/docs/sdks/javascript/) in a [Nuxt](https://nuxt.com) application.

For Featurevisor documentation, visit [https://featurevisor.com](https://featurevisor.com).
The application loads a published Featurevisor datafile once, keeps a shared SDK instance, and evaluates `my_feature` during rendering.

## Setup

Make sure to install the dependencies:

```
$ npm install
```sh
npm ci
```

## Development Server

Start the development server on `http://localhost:3000`:

```
$ npm run dev
```sh
npm run dev
```

## Production

Build the application for production:

```
$ npm run build
```sh
npm run build
```

Locally preview production build:

```
$ npm run preview
```sh
npm run preview
```

Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
5 changes: 4 additions & 1 deletion app.vue → app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const isEnabled = f.isEnabled(featureKey, context);
<p v-if="isEnabled">Feature is enabled!</p>
<p v-else>Feature is disabled :(</p>

<p>Learn more at <a href="https://featurevisor.com">https://featurevisor.com</a></p>
<p>
Learn more at
<a href="https://featurevisor.com">https://featurevisor.com</a>
</p>
</div>
</template>

Expand Down
33 changes: 33 additions & 0 deletions app/featurevisor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createFeaturevisor, type Featurevisor } from "@featurevisor/sdk";

const DATAFILE_URL =
"https://featurevisor-example-cloudflare.pages.dev/production/featurevisor-tag-all.json";

let instance: Featurevisor | undefined;
let pendingInstance: Promise<Featurevisor> | undefined;

export async function getInstance() {
if (instance) {
return instance;
}

if (!pendingInstance) {
pendingInstance = fetch(DATAFILE_URL)
.then((response) => {
if (!response.ok) {
throw new Error(`Request failed with status ${response.status}`);
}

return response.json();
})
.then((datafile) => {
instance = createFeaturevisor({ datafile });
return instance;
})
.finally(() => {
pendingInstance = undefined;
});
}

return pendingInstance;
}
20 changes: 0 additions & 20 deletions featurevisor.ts

This file was deleted.

2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export default defineNuxtConfig({
build: {
transpile: ["@featurevisor/sdk"],
},
})
});
Loading