3.0.1 • Published 1 year ago

@roadiz/nuxt-module v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

nuxt-module

Nuxt Typescript module for Roadiz API client.

Usage

yarn add @roadiz/nuxt-module

Configuration

Add module in you nuxt.config.js file and fill you API configuration values in publicRuntimeConfig:

// nuxt.config.js

modules: [
    '@roadiz/nuxt-module'
],
    
publicRuntimeConfig: {
    roadiz: {
        baseURL: 'https://myroadizapi.test/api/1.0',
        apiKey: 'xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx',
        allowClientPreview: true,
        debug: false,
        origin: 'https://mywebsite.test'
    }
}

Make sure to add a default origin for any server side requests if you Roadiz API is secured by RefererRegex.

Add typescript declarations in your tsconfig.json:

{
  "compilerOptions": {
    "types": [
      "@roadiz/nuxt-module"
    ]
  }
}

API SDK

Here is a simple example how to fetch Roadiz API content during asyncData:

async asyncData({ $roadiz, route, req }: Context): Promise<object | void> | object | void {
    const path = route.params.pathMatch
    const response = await $roadiz.getWebResponseByPath(path)
    const pageData = response.data
    const altLinks = await $roadiz.getAlternateLinks(response)
    
    return {
        pageData,
        altLinks
    }
}

Client previewing

If you enable allowClientPreview config, NuxtRoadizApi will append _preview and token query parameters to any API request to your Roadiz API. _preview parameter will be passed-through, and token parameter will be added as Authorization: Bearer ${token} header.

If your user is currently previewing with a JWT, $roadiz.previewingJwt (RoadizPreviewJwt) object will be available to display information on your website.

3.0.1

1 year ago

3.0.0

1 year ago

2.1.5

1 year ago

1.0.1

2 years ago

2.1.4

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

0.2.0

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago