Skip to content

Commit

Permalink
improve: LDP-2644: Add option to disable form handler (#271)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vloss3 authored Nov 20, 2024
1 parent f3710c1 commit 78c79f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ModuleOptions {
passThroughHeaders?: string[]
exposeAPIRouteRules?: boolean
serverLogLevel?: boolean | 'info' | 'error'
disableFormHandler?: boolean
}

export default defineNuxtModule<ModuleOptions>({
Expand All @@ -43,6 +44,7 @@ export default defineNuxtModule<ModuleOptions>({
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
Expand All @@ -63,15 +65,18 @@ export default defineNuxtModule<ModuleOptions>({
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)

Expand Down

0 comments on commit 78c79f0

Please sign in to comment.