mirror of
https://github.com/praveentcom/openproxy.git
synced 2026-07-25 13:21:07 +02:00
Enhance logging and update README for SSRF warning
- Updated console log messages in cost.ts and proxy.ts for clarity and consistency. - Added important SSRF warning in README.md regarding localhost access issues with certain clients, along with solutions using external proxy services.
This commit is contained in:
@@ -49,6 +49,9 @@ OpenProxy uses path prefixes for clean provider detection:
|
|||||||
| `/openai/*` | `OPENAI_UPSTREAM_URL/*` | `Authorization: Bearer <key>` |
|
| `/openai/*` | `OPENAI_UPSTREAM_URL/*` | `Authorization: Bearer <key>` |
|
||||||
| `/anthropic/*` | `ANTHROPIC_UPSTREAM_URL/*` | `x-api-key: <key>` or `Authorization: Bearer <key>` |
|
| `/anthropic/*` | `ANTHROPIC_UPSTREAM_URL/*` | `x-api-key: <key>` or `Authorization: Bearer <key>` |
|
||||||
|
|
||||||
|
### SSRF Warning [Important]
|
||||||
|
|
||||||
|
Some clients (e.g. Cursor) may block access to `localhost` or `127.0.0.1` URLs. If you encounter this issue, you can use an external proxy service like `ngrok` to open up your `localhost:3007` port to a public domain. This will enable you to use OpenProxy with such services.
|
||||||
|
|
||||||
### PostgreSQL Logging
|
### PostgreSQL Logging
|
||||||
|
|
||||||
@@ -96,12 +99,26 @@ For example, to use Z.AI or other Anthropic-compatible providers with Claude Cod
|
|||||||
export ANTHROPIC_UPSTREAM_URL="https://api.z.ai/api/anthropic"
|
export ANTHROPIC_UPSTREAM_URL="https://api.z.ai/api/anthropic"
|
||||||
export DATABASE_URL="postgresql://user:password@localhost:5432/database_name"
|
export DATABASE_URL="postgresql://user:password@localhost:5432/database_name"
|
||||||
pnpm dev
|
pnpm dev
|
||||||
|
|
||||||
# Configure Claude Code to use:
|
|
||||||
# API Base URL: http://localhost:3007/anthropic
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using with OpenAI-compatible clients
|
Configure Claude Code to use the following URL: `http://localhost:3007/anthropic`
|
||||||
|
|
||||||
|
### Using with Cursor
|
||||||
|
|
||||||
|
For example, to use Z.AI or other Anthropic-compatible providers with Cursor:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export ANTHROPIC_UPSTREAM_URL="https://api.z.ai/api/anthropic"
|
||||||
|
export DATABASE_URL="postgresql://user:password@localhost:5432/database_name"
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
> Cursor blocks access to `localhost` or `127.0.0.1` URLs by default. You can use an external proxy service like `ngrok` to open up your `localhost:3007` port to a public domain. Refer to the [SSRF Warning](#ssrf-warning-important) for more details.
|
||||||
|
|
||||||
|
Configure Cursor to use the following URL for OpenAI API requests: `http://public-domain.ngrok-free.app/openai`
|
||||||
|
Configure Cursor to use the following URL for Anthropic API requests: `http://public-domain.ngrok-free.app/anthropic`
|
||||||
|
|
||||||
|
### Using with other OpenAI-compatible clients
|
||||||
|
|
||||||
For example, to use Z.AI or other OpenAI-compatible providers with OpenAI-compatible clients:
|
For example, to use Z.AI or other OpenAI-compatible providers with OpenAI-compatible clients:
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export async function loadHeliconeCosts(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
heliconeCostsLoaded = true;
|
heliconeCostsLoaded = true;
|
||||||
console.log(`\x1b[36m 🌎 Loaded ${data.metadata.total_models} model costs from Helicone\x1b[0m`);
|
console.log(`\x1b[96m 🌎 Loaded ${data.metadata.total_models} model costs from Helicone API\x1b[0m`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(`\x1b[33m ⚠️ Failed to load Helicone costs: ${error instanceof Error ? error.message : error}\x1b[0m`);
|
console.warn(`\x1b[33m ⚠️ Failed to load Helicone costs: ${error instanceof Error ? error.message : error}\x1b[0m`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ async function persistDatabaseRecord(data: Record<string, any>) {
|
|||||||
*/
|
*/
|
||||||
const server = http.createServer(async (req: IncomingMessage, res: ServerResponse) => {
|
const server = http.createServer(async (req: IncomingMessage, res: ServerResponse) => {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
console.log(`[\x1b[30m${new Date().toISOString()}\x1b[0m] \x1b[93m${req.method} \x1b[0m\x1b[94m${req.url}\x1b[0m`);
|
||||||
try {
|
try {
|
||||||
const url = new URL(req.url || "/", `http://${req.headers.host}`);
|
const url = new URL(req.url || "/", `http://${req.headers.host}`);
|
||||||
const path = url.pathname;
|
const path = url.pathname;
|
||||||
@@ -483,10 +484,10 @@ async function startServer() {
|
|||||||
await loadHeliconeCosts();
|
await loadHeliconeCosts();
|
||||||
|
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
console.log(`\n\x1b[32mOpenProxy upstream connections activated ⟣⟢\x1b[0m\n`);
|
console.log(`\n\x1b[32mOpenProxy ready... ⟣⟢\x1b[0m\n`);
|
||||||
|
|
||||||
if (OPENAI_UPSTREAM_URL) console.log(`\x1b[34m 📡 http://localhost:${PORT}/openai/* → ${OPENAI_UPSTREAM_URL}\x1b[0m`);
|
if (OPENAI_UPSTREAM_URL) console.log(`\x1b[94m 📡 http://localhost:${PORT}/openai/* → ${OPENAI_UPSTREAM_URL}\x1b[0m`);
|
||||||
if (ANTHROPIC_UPSTREAM_URL) console.log(`\x1b[34m 📡 http://localhost:${PORT}/anthropic/* → ${ANTHROPIC_UPSTREAM_URL}\x1b[0m\n`);
|
if (ANTHROPIC_UPSTREAM_URL) console.log(`\x1b[94m 📡 http://localhost:${PORT}/anthropic/* → ${ANTHROPIC_UPSTREAM_URL}\x1b[0m\n`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user