To use a forward proxy for all external requests made during the SSR process and for external requests made by the FSXA proxy backend, the package global-agent
can be used.
-
To install
global-agent
use:npm i --save global-agent npm i --save-dev @types/global-agent
Or install as a dev dependency:
npm i --save-dev global-agent @types/global-agent
-
The
global-agent
package needs to be bootstrapped, e.g. using an inline module function (nuxt.config.ts):import * as globalAgent from 'global-agent' .. const config: NuxtConfig = { .., modules: [ .., function () { this.nuxt.hook('listen', async () => globalAgent.bootstrap()) } ], .. } export default config
Or bootstrap only during development:
import * as globalAgent from 'global-agent' .. const config: NuxtConfig = { .., modules: [ .., function () { this.nuxt.hook('listen', async () => { if (this.options.dev) { globalAgent.bootstrap() } }) } ], .. } export default config
-
Finally, specify the URI of the proxy server using the environment variable
GLOBAL_AGENT_HTTP_PROXY
and exclude requests tolocalhost
usingGLOBAL_AGENT_NO_PROXY
:export GLOBAL_AGENT_NO_PROXY=localhost export GLOBAL_AGENT_HTTP_PROXY=http://localhost:8080 npm run dev