---
title: Proxy
sidebar_position: 5
---
# Proxy

## Local Proxy

Modern.js provides a way to configure the development proxy in [`tools.devServer`](/configure/app/tools/dev-server). For example, to proxy the local interface to an online address:

```ts title="modern.config.ts"
import { defineConfig } from '@modern-js/app-tools';

export default defineConfig({
  tools: {
    devServer: {
      proxy: {
        '/go/api': {
          target: 'http://www.example.com/',
          changeOrigin: true,
        },
      },
    },
  },
});
```

When access `http://localhost:8080/go/api`, the response content will be returned from [http://www.example.com/](http://www.example.com/).

:::info
For more detail, see [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware).
:::

## Global Proxy

import GlobalProxy from "@site-docs-en/components/global-proxy"

<GlobalProxy />

## BFF Proxy

By configuring [`bff.proxy`](/configure/app/bff/proxy), BFF API requests can be proxied to a specified service. Unlike the other proxy methods above, it can be used in the production environment:

```ts title="modern.config.ts"
export default defineConfig({
  bff: {
    proxy: {
      '/api/v1': 'https://cnodejs.org',
    },
  },
});
```

For example, when using BFF function in the code, the final request `http://localhost:8080/api/v1/topics` will be automatically proxied to `https://cnodejs.org/api/v1/topics`:

```js
import getTopics from '@api/v1/topics';

getTopics();
```
