From 2ad4bb3fbef95c66e04eaf33a206237949a579e6 Mon Sep 17 00:00:00 2001 From: Ebenezer Date: Tue, 31 Mar 2026 13:50:42 +0800 Subject: [PATCH] done with backend --- backend/.env | 7 +------ backend/.env.example | 2 +- backend/auth-api.js | 16 +++++++++------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/backend/.env b/backend/.env index f3344d6..b50e783 100644 --- a/backend/.env +++ b/backend/.env @@ -1,11 +1,6 @@ -PORT=3010 DB_HOST=nw.sgcode.cn DB_PORT=21434 DB_USER=root DB_PASSWORD=root DB_NAME=opencoze - -# Coze SSO integration (must match Coze backend config) -SSO_SHARED_SECRET=dev-sso-shared-secret-change-me -COZE_HOST=http://nw.sgcode.cn:18888 - +COZE_HOST=http://localhost:8888 \ No newline at end of file diff --git a/backend/.env.example b/backend/.env.example index be57ba1..ed7f6f5 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -26,4 +26,4 @@ DB_TABLE_USER=user # Shared secret used to sign SSO JWTs (must match Coze backend SSO_SHARED_SECRET) SSO_SHARED_SECRET=change-this-sso-secret # Base URL of your Coze host (including scheme and port) -COZE_HOST=http://nw.sgcode.cn:18888 +COZE_HOST=http://localhost:8888 diff --git a/backend/auth-api.js b/backend/auth-api.js index 1f6bb94..27e8cb5 100644 --- a/backend/auth-api.js +++ b/backend/auth-api.js @@ -10,6 +10,7 @@ dotenv.config(); const app = express(); const port = 3010; +const cozeHost = (process.env.COZE_HOST || 'http://localhost:8888').replace(/\/+$/, ''); app.use( cors({ @@ -232,7 +233,7 @@ app.get('/api/coze/space-url', async (req, res) => { return; } - const url = `http://nw.sgcode.cn:18888/space/${space.id}/develop`; + const url = `${cozeHost}/space/${space.id}/develop`; res.json({ url, spaceId: space.id, user: user.email || user.unique_name || user.name }); } catch (error) { console.error('Resolve Coze space URL failed:', error); @@ -250,7 +251,6 @@ app.get('/api/coze/sso-login', (req, res) => { } const secret = process.env.SSO_SHARED_SECRET; - const cozeHost = process.env.COZE_HOST || 'http://nw.sgcode.cn:18888'; if (!secret) { res.status(500).json({ message: 'SSO is not configured on server (missing SSO_SHARED_SECRET)' }); @@ -264,7 +264,7 @@ app.get('/api/coze/sso-login', (req, res) => { ); const nextPath = encodeURIComponent('/space'); - const redirectUrl = `${cozeHost.replace(/\/+$/, '')}/api/passport/web/sso/exchange/?token=${encodeURIComponent( + const redirectUrl = `${cozeHost}/api/passport/web/sso/exchange/?token=${encodeURIComponent( token )}&next=${nextPath}`; @@ -277,11 +277,13 @@ app.get('/api/coze/sso-login', (req, res) => { ensureUsersTable() .then(() => { + console.log('Database initialization completed.'); + }) + .catch((error) => { + console.error('Failed to initialize database (server will still start):', error); + }) + .finally(() => { app.listen(port, () => { console.log(`Auth API running at http://localhost:${port}`); }); - }) - .catch((error) => { - console.error('Failed to initialize database:', error); - process.exit(1); });