# Proxy Setup

If ad blockers or network policies block the SDK assets, use a proxy on your domain. The SDK supports a `proxy.baseUrl` that routes API calls through your server.

## 1) Configure the SDK

### NPM

```javascript
import { Elements } from '@liquidcommerce/elements-sdk';

const client = await Elements('YOUR_API_KEY', {
  env: 'production',
  proxy: {
    baseUrl: 'https://yoursite.com/api/elements-proxy'
  }
});
```

### CDN (Next.js example)

```jsx
'use client';

import { useEffect } from 'react';
import { Elements } from '@liquidcommerce/elements-sdk';

export default function ProductPage() {
  useEffect(() => {
    (async () => {
      const client = await Elements('YOUR_API_KEY', {
        env: 'production',
        proxy: { baseUrl: '/api/elements-proxy' }
      });

      await client.injectProductElement([
        { containerId: 'product', identifier: '00619947000020' }
      ]);
    })();
  }, []);

  return <div id="product"></div>;
}
```

## 2) Create the Proxy Endpoint

Your endpoint should forward requests to the LiquidCommerce Elements API, preserving method, headers, and body.

### Minimal Express Example

```javascript
import express from 'express';
import fetch from 'node-fetch';

const app = express();
app.use(express.json());

app.all('/api/elements-proxy/*', async (req, res) => {
  const targetPath = req.params[0];
  const targetUrl = `https://api.liquidcommerce.us/${targetPath}`;

  const response = await fetch(targetUrl, {
    method: req.method,
    headers: {
      ...req.headers,
      host: 'api.liquidcommerce.us'
    },
    body: ['GET', 'HEAD'].includes(req.method) ? undefined : JSON.stringify(req.body)
  });

  const data = await response.text();
  res.status(response.status).send(data);
});

app.listen(3000, () => {
  console.log('Proxy listening on port 3000');
});
```

## Notes

- Keep your API key server-side whenever possible.
- Ensure CORS allows your storefront domain to call the proxy.

## Related Docs

- [Installation](../getting-started/installation.md)
- [Client API](../api/client.md)
