UNPKG

@attributech/nuxt-drupal-utils

Version:

Shared utilities for Nuxt 3 projects with Drupal backend

107 lines (80 loc) 2.44 kB
# @attributech/nuxt-drupal-utils [![Tests](https://github.com/attributech/nuxt-drupal-utils/actions/workflows/tests.yml/badge.svg)](https://github.com/attributech/nuxt-drupal-utils/actions/workflows/tests.yml) Shared utilities for Nuxt projects with Drupal backend. ## Installation ```bash 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: ```js 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`: ```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: ```js // 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: ```vue <!-- 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