0.2.3 • Published 8 months ago
@attributech/nuxt-drupal-utils v0.2.3
@attributech/nuxt-drupal-utils
Shared utilities for Nuxt projects with Drupal backend.
Installation
npm install @attributech/nuxt-drupal-utilsFeatures
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 URLgetAppUrl: Determines the application URLgetServerUrl: Determines the server URLgetLagoonDevelopmentDomain: 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