Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
nuxtjs-drupal-ce
Advanced tools
[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![ci](https://github.com/drunomics/nuxtjs-drupal-ce/actions/workflows/ci.yml/badge.svg?branch=2.x)](https://github.com/drunomics/nuxtjs-drupal-c
Connects Nuxt v3 with Drupal via the Lupus Custom Elements Renderer
Please refer to https://www.drupal.org/project/lupus_decoupled for more info.
The 2.x version of the module is compatible with Nuxt 3. For a Nuxt 2 compatible version, please checkout the 1.x version
npx nuxi@latest init <project-name>
nuxtjs-drupal-ce
module to your Nuxt projectnpx nuxi@latest module add drupal-ce
nuxtjs-drupal-ce
in your nuxt.config.js
export default defineNuxtConfig({
modules: [
'nuxtjs-drupal-ce',
],
drupalCe: {
drupalBaseUrl: 'https://your-drupal.example.com',
// more options...
}
})
The module defaults work well with Lupus Decoupled Drupal - in that case setting the
drupalBaseUrl
is enough to get started.
rm -f app.vue && npx nuxt-drupal-ce-init
drupalBaseUrl
: The Drupal base URL, e.g. https://example.com:8080
. Required.
serverDrupalBaseUrl
: Optionally, an alternative drupal base URL to apply in server context.
ceApiEndpoint
: The custom elements API endpoint. Defaults to /ce-api
.
fetchOptions
: The default fetchOptions
to apply when fetching from the Drupal. Defaults to { credentials: 'include' }
.
fetchProxyHeaders
: The HTTP request headers to pass through to Drupal, via useRequestHeaders. Defaults to ['cookie']
.
menuEndpoint
: The menu endpoint pattern used for fetching menus. Defaults to 'api/menu_items/$$$NAME$$$' as fitting
to the API provided by the Rest menu items Drupal module.
$$$NAME$$$
is replaced by the menu name being fetched.
menuBaseUrl
: The menu base URL. Defaults to drupalBaseUrl + ceApiEndpoint.
addRequestContentFormat
: If specified, the given value is added as _content_format
URL parameter to requests. Disabled by default.
addRequestFormat
: If set to true
, the _format=custom_elements
URL parameter
is added automatically to requests. Defaults to false
.
customErrorPages
: By default, error pages provided by Drupal (e.g. 403, 404 page) are shown,
while keeping the right status code. By enabling customErrorPages, the regular Nuxt error
pages are shown instead, such that the pages can be customized with Nuxt. Defaults to false
.
useLocalizedMenuEndpoint
: If enabled, the menu endpoint will use a language prefix as configured by nuxtjs/i18n module. Defaults to true
.
serverApiProxy
: If enabled, the module will create a Nitro server handler that proxies API requests to Drupal backend. Defaults to true
for SSR (it's disabled for SSG).
passThroughHeaders
: Response headers to pass through from Drupal to the client. Defaults to ['cache-control', 'content-language', 'set-cookie', 'x-drupal-cache', 'x-drupal-dynamic-cache']. Note: This is only available in SSR mode.
serverLogLevel
: The log level to use for server-side logging. Defaults to 'info'. Options:
disableFormHandler
: If set to true
, the form handler middleware will be disabled. Defaults to false
.
Runtime config values can be overridden with environment variables via NUXT_PUBLIC_
prefix. Supported runtime overrides:
drupalBaseUrl
-> NUXT_PUBLIC_DRUPAL_CE_DRUPAL_BASE_URL
serverDrupalBaseUrl
-> NUXT_PUBLIC_DRUPAL_CE_SERVER_DRUPAL_BASE_URL
menuBaseUrl
-> NUXT_PUBLIC_DRUPAL_CE_MENU_BASE_URL
ceApiEndpoint
-> NUXT_PUBLIC_DRUPAL_CE_CE_API_ENDPOINT
Generally, custom elements are rendered as dynamic components and simply need to be registered as global components.
The components should be placed in ~/components/global
, refer to the /playground
directory for an example.
For example, for the custom element node-article-teaser
a global component node-article-teaser.vue
would be
picked up for rendering.
We recommend to name the components lowercase using kebap-case, such that there is a clear 1:1 mapping between
custom element names used in the API response and the frontend components. For
example use custom-element-name.vue
instead of CustomElementName.vue
. Both variants work though.
When using JSON-based rendering of custom elements, the module offers fallback component support. If a custom element lacks a corresponding Vue component, the module attempts to find a suitable default component.
-
-separated prefix from the element name.--default
suffix.This approach allows for generic default components like drupal-form--default.vue
to be used for specific elements such as drupal-form-user-login-form.vue
. For customization, developers can simply copy and modify the default component as needed.
When a specific component isn't found, the module searches for a default component by progressively removing segments from the custom element name. For example when rendering the custom element node-custom-view
it looks for components in the following order:
x node-custom-view.vue
x node-custom-view--default.vue
x node-custom--default.vue
✓ node--default.vue
The following options are deprecated and only there for improved backwards compatibility.
baseURL
: The base URL of the Drupal /ce-api endpoint, e.g. http://localhost:8888/ce-api.
If set, drupalBaseUrl
is set with the origin of the provided URL.The module provides a default error handler for the fetchPage
and fetchMenu
methods:
fetchPage
: Throws an error with the status code and message provided by Drupal.fetchMenu
: Logs an error message to the console and displays a message in the frontend.You have the option to override the default error handlers by using a parameter when calling the fetch
methods.
fetchPage
:
<script lang="ts" setup>
const { fetchPage } = useDrupalCe()
function customPageError (error: Record<string, any>) {
throw createError({ statusCode: error.value.statusCode, statusMessage: 'No access.', data: {}, fatal: true })
}
const page = await fetchPage(useRoute().path, { query: useRoute().query }, customPageError)
</script>
fetchMenu
:
<script lang="ts" setup>
const { fetchMenu } = useDrupalCe()
const { getMessages } = useDrupalCe()
const messages = getMessages()
function customMenuError (error: Record<string, any>) {
messages.value.push({
type: 'error',
message: `Menu error: Unavailable. ${error.value.statusCode}`
})
}
const mainMenu = await fetchMenu('main', {}, customMenuError)
</script>
Note: The error
parameter is optional and can be omitted.
The following options were support in 1.x but got dropped:
addVueCompiler
: This is necessary if you want to render custom elements markup on runtime;
i.e. use the 'markup' content format. Instead, the vue runtime compiler can be enabled in via
Nuxt config, see here.
axios
: Options to pass-through to the drupal-ce
axios instance. Use fetchOptions
instead.
npm install
.npm run dev:prepare
to generate type stubs.npm run dev
to start playground in development mode.https://8080-shaal-drupalpod-8m3z0ms7mb6.ws-eu67.gitpod.io/ce-api
https://8080-shaal-drupalpod-8m3z0ms7mb6.ws-eu67.gitpod.io/ce-api
Development sponsored by drunomics hello@drunomics.com
FAQs
[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![ci](https://github.com/drunomics/nuxtjs-drupal-ce/actions/workflows/ci.yml/badge.svg?branch=2.x)](https://github.com/drunomics/nuxtjs-drupal-c
The npm package nuxtjs-drupal-ce receives a total of 226 weekly downloads. As such, nuxtjs-drupal-ce popularity was classified as not popular.
We found that nuxtjs-drupal-ce demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.