0.2.3 • Published 8 months ago

@attributech/nuxt-drupal-utils v0.2.3

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@attributech/nuxt-drupal-utils

Tests

Shared utilities for Nuxt projects with Drupal backend.

Installation

npm install @attributech/nuxt-drupal-utils

Features

This package provides utility functions for handling URLs in Nuxt projects with Drupal backends, particularly for projects using Lagoon hosting:

  • getApiUrl: Determines the API endpoint URL
  • getAppUrl: Determines the application URL
  • getServerUrl: Determines the server URL
  • getLagoonDevelopmentDomain: Builds a Lagoon domain for development environments

Usage

Direct Import

You can import the utilities directly:

import { getApiUrl, getServerUrl, getAppUrl } from '@attributech/nuxt-drupal-utils'

const serverUrl = getServerUrl('https://default-backend.com')
const apiUrl = getApiUrl('https://default-backend.com')
const appUrl = getAppUrl('https://www.example.com')

This is particularly useful in nuxt.config.js:

// Nuxt 2
import { getApiUrl, getServerUrl, getAppUrl } from '@attributech/nuxt-drupal-utils'

export default {
  publicRuntimeConfig: {
    serverUrl: getServerUrl('https://default-backend.com'),
    apiUrl: getApiUrl('https://default-backend.com'),
    appUrl: getAppUrl('https://www.example.com')
  }
}

// Nuxt 3
import { getApiUrl, getServerUrl, getAppUrl } from '@attributech/nuxt-drupal-utils'

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      serverUrl: getServerUrl('https://default-backend.com'),
      apiUrl: getApiUrl('https://default-backend.com'),
      appUrl: getAppUrl('https://www.example.com')
    }
  }
})

As a Nuxt Module

You can also use it as a Nuxt module to auto-inject the utilities:

// Nuxt 2 with Bridge
export default {
  buildModules: [
    '@attributech/nuxt-drupal-utils/module'
  ]
}

// Nuxt 3
export default defineNuxtConfig({
  modules: [
    '@attributech/nuxt-drupal-utils/module'
  ]
})

Then in your components:

<!-- Nuxt 2 -->
<script>
export default {
  mounted() {
    const apiUrl = this.$getApiUrl('https://default-backend.com')
    console.log(apiUrl)
  }
}
</script>

<!-- Nuxt 3 -->
<script setup>
const { $getApiUrl } = useNuxtApp()
const apiUrl = $getApiUrl('https://default-backend.com')
</script>

License

MIT

0.2.3

8 months ago

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago