Provide custom Headers

There are several levels of header configuration available.

Page Response Headers

To set up a custom header on a Node.js Response, you can leverage the built-in h3 features.

Read More here

plugins/setResponseHeader.ts
import { setResponseHeader, setResponseHeaders } from 'h3'

export default defineNuxtPlugin(() => {
  if (import.meta.server) {
    // single
    setResponseHeader(useRequestEvent(), 'my-custom-header', 'true')
    // or multiple
    setResponseHeaders(useRequestEvent(), {
      'my-custom-header2': 'true',
      'my-custom-header3': 'true'
    })
  }
})
Please be aware that you can use the setResponseHeader functions only in a Server Side Context.

TYPO3 Requests Headers

To set up a custom header for TYPO3 Requests, you can utilize the nuxt-typo3 composable.

plugins/setRequestHeader.ts
export default defineNuxtPlugin(() => {
  const { setHeaders } = useT3Api()

  setHeaders({
    'my-custom-header': 'true'
  })
})
The setHeaders function is responsible for setting up headers for all requests made by the nuxt-typo3 library, including InitialData, PageData, and custom endpoints. If you want to set up a header for a specific endpoint, please use interceptors.

Proxy Headers from TYPO3 to Node.js

In the Server-Side Context, we don't proxy headers from TYPO3 to the Node.js Response by default.

However, there might be situations where you'd want to do this. For example, you may need to proxy the Set-Cookie header from the TYPO3 Response (in SSR) to the Node.js Page Response in order to handle Frontend Login.

To proxy specific headers, you can configure proxyHeaders option (array of strings).

nuxt.config.ts
export default defineNuxtConfig({
  modules: [nuxtTypo3],
  typo3: {
    api: {
      proxyHeaders: ['set-cookie']
    },
  },
})
All headers should be provided as lower-case.

Proxy Request Headers to TYPO3

In the Server-Side Context, we don't proxy headers from Node.js Requests to TYPO3 API.

If you want to do this, you can configure proxyReqHeaders option (array of strings).

nuxt.config.ts
export default defineNuxtConfig({
  modules: [nuxtTypo3],
  typo3: {
    api: {
      proxyReqHeaders: ['referer'],
    },
  },
})
All headers should be provided as lower-case.