N
Nuxt2mo ago
Kyoko

How to add headers into route middleware of Nuxt3

Hi I am trying to change the request headers using route middleware. The docs is not clear at all please help???
1 Reply
zsilbi
zsilbi2mo ago
Hi! I'll also answer it here if others are looking for it:
import { setHeader } from 'h3';

export default defineNuxtRouteMiddleware((to) => {
if (import.meta.server) {
setHeader(useRequestEvent(), 'x-client', 'set in route middleware');
}
});
import { setHeader } from 'h3';

export default defineNuxtRouteMiddleware((to) => {
if (import.meta.server) {
setHeader(useRequestEvent(), 'x-client', 'set in route middleware');
}
});
Want results from more Discord servers?
Add your server