turns out we simply use nitro.devProxy.
At first hostRewrite option seems to rewrite request header, but it actually rewrites host field of the response header. So we need to manually pass headers option.
https://github.com/http-party/node-http-proxy
const endpoint = 'https://api.example.com/graphql'
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
nitro: {
devProxy: {
// GraphQL Proxy Endpoint
'/api/graphql': {
target: endpoint,
headers: {
host: 'api.example.com',
},
cookieDomainRewrite: '',
},
},
},
runtimeConfig: {
graphqlEndpoint: endpoint,
public: {
graphqlEndpoint: 'http://localhost:3000/api/graphql',
},
},
})below snippets are just for reference.