From 78c79f03c271a4fa35bd89a67d4c26a5c5a5d227 Mon Sep 17 00:00:00 2001 From: Alexandru Teodor Date: Wed, 20 Nov 2024 17:23:23 +0200 Subject: [PATCH] improve: LDP-2644: Add option to disable form handler (#271) * improve: LDP-2644: Add option to skip form handler * LDP-2644: Add option to disable form handler middleware * LDP-2644: Formatting * LDP-2644: Update README * LDP-2644: Update README --- README.md | 2 ++ src/module.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d09b6216..c43e455c 100755 --- a/README.md +++ b/README.md @@ -107,6 +107,8 @@ is added automatically to requests. Defaults to `false`. - 'info': Log all server requests and errors. - 'error': Log only errors. +- `disableFormHandler`: If set to `true`, the form handler middleware will be disabled. Defaults to `false`. + ## Overriding options with environment variables Runtime config values can be overridden with environment variables via `NUXT_PUBLIC_` prefix. Supported runtime overrides: diff --git a/src/module.ts b/src/module.ts index 42c0ddf2..897deca0 100644 --- a/src/module.ts +++ b/src/module.ts @@ -19,6 +19,7 @@ export interface ModuleOptions { passThroughHeaders?: string[] exposeAPIRouteRules?: boolean serverLogLevel?: boolean | 'info' | 'error' + disableFormHandler?: boolean } export default defineNuxtModule({ @@ -43,6 +44,7 @@ export default defineNuxtModule({ serverApiProxy: true, passThroughHeaders: ['cache-control', 'content-language', 'set-cookie', 'x-drupal-cache', 'x-drupal-dynamic-cache'], serverLogLevel: 'info', + disableFormHandler: false, }, setup(options, nuxt) { const nuxtOptions = nuxt.options as NuxtOptionsWithDrupalCe @@ -63,15 +65,18 @@ export default defineNuxtModule({ addServerPlugin(resolve(runtimeDir, 'server/plugins/errorLogger')) } addImportsDir(resolve(runtimeDir, 'composables/useDrupalCe')) - addServerHandler({ - handler: resolve(runtimeDir, 'server/middleware/drupalFormHandler'), - }) + if (!options.disableFormHandler) { + addServerHandler({ + handler: resolve(runtimeDir, 'server/middleware/drupalFormHandler'), + }) + } const publicOptions = { ...options } // Server options are not needed in the client bundle. delete publicOptions.serverLogLevel delete publicOptions.passThroughHeaders delete publicOptions.exposeAPIRouteRules + delete publicOptions.disableFormHandler nuxt.options.runtimeConfig.public.drupalCe = defu(nuxt.options.runtimeConfig.public.drupalCe ?? {}, publicOptions)