Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/proxy/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Koa, { type Context, type Next } from 'koa'
import Router from '@koa/router'
import bodyParser from 'koa-bodyparser'
import { Server as HttpServer } from 'http'
import { app } from 'electron'
import routes from './routes'
import managementRoutes from './routes/management'
import { proxyStatusManager } from './status'
Expand Down Expand Up @@ -41,7 +42,7 @@ export class ProxyServer {
this.app.use(async (ctx, next) => {
ctx.set('Access-Control-Allow-Origin', '*')
ctx.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
ctx.set('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With')
ctx.set('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With, X-API-Key, X-Management-Secret, X-Web-Search, X-Reasoning-Effort, X-Deep-Research')
ctx.set('Access-Control-Max-Age', '86400')

if (ctx.method === 'OPTIONS') {
Expand Down Expand Up @@ -163,7 +164,7 @@ export class ProxyServer {
this.router.get('/', async (ctx) => {
ctx.body = {
name: 'Chat2API Proxy',
version: '1.1.2',
version: app.getVersion(),
description: 'OpenAI API compatible proxy service',
endpoints: [
'POST /v1/chat/completions',
Expand Down
3 changes: 2 additions & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,9 @@ function resolveLocalManagementApiBaseUrl(config: AppConfig): string {
const host = configuredHost === '0.0.0.0' || configuredHost === '::' || configuredHost === '[::]'
? '127.0.0.1'
: configuredHost
const managementApiPort = config.managementApi?.managementApiPort || config.proxyPort

return `http://${host}:${config.proxyPort}/v0/management`
return `http://${host}:${managementApiPort}/v0/management`
}

const toolCallingAPI = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export function ManagementApiSettings() {
return secret.slice(0, 4) + '****' + secret.slice(-4)
}

const apiEndpoint = `http://127.0.0.1:${proxyPort}/v0/management`
const managementApiPort = config.managementApiPort || proxyPort
const apiEndpoint = `http://127.0.0.1:${managementApiPort}/v0/management`

if (isLoading) {
return (
Expand Down
7 changes: 4 additions & 3 deletions tests/renderer/header-proxy-address.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ test('tool calling smoke uses a local management API URL that is actually served

assert.match(preloadSource, /function resolveLocalManagementApiBaseUrl\(config: AppConfig\)/)
assert.match(preloadSource, /configuredHost === '0\.0\.0\.0'/)
assert.match(preloadSource, /return `http:\/\/\$\{host\}:\$\{config\.proxyPort\}\/v0\/management`/)
assert.doesNotMatch(preloadSource, /managementApi\?\.managementApiPort \|\| config\.proxyPort/)
assert.match(managementSettingsSource, /const apiEndpoint = `http:\/\/127\.0\.0\.1:\$\{proxyPort\}\/v0\/management`/)
assert.match(preloadSource, /managementApi\?\.managementApiPort \|\| config\.proxyPort/)
assert.match(preloadSource, /return `http:\/\/\$\{host\}:\$\{managementApiPort\}\/v0\/management`/)
assert.match(managementSettingsSource, /config\.managementApiPort \|\| proxyPort/)
assert.match(managementSettingsSource, /const apiEndpoint = `http:\/\/127\.0\.0\.1:\$\{managementApiPort\}\/v0\/management`/)
})