done with backend
This commit is contained in:
@@ -1,11 +1,6 @@
|
|||||||
PORT=3010
|
|
||||||
DB_HOST=nw.sgcode.cn
|
DB_HOST=nw.sgcode.cn
|
||||||
DB_PORT=21434
|
DB_PORT=21434
|
||||||
DB_USER=root
|
DB_USER=root
|
||||||
DB_PASSWORD=root
|
DB_PASSWORD=root
|
||||||
DB_NAME=opencoze
|
DB_NAME=opencoze
|
||||||
|
COZE_HOST=http://localhost:8888
|
||||||
# Coze SSO integration (must match Coze backend config)
|
|
||||||
SSO_SHARED_SECRET=dev-sso-shared-secret-change-me
|
|
||||||
COZE_HOST=http://nw.sgcode.cn:18888
|
|
||||||
|
|
||||||
@@ -26,4 +26,4 @@ DB_TABLE_USER=user
|
|||||||
# Shared secret used to sign SSO JWTs (must match Coze backend SSO_SHARED_SECRET)
|
# Shared secret used to sign SSO JWTs (must match Coze backend SSO_SHARED_SECRET)
|
||||||
SSO_SHARED_SECRET=change-this-sso-secret
|
SSO_SHARED_SECRET=change-this-sso-secret
|
||||||
# Base URL of your Coze host (including scheme and port)
|
# Base URL of your Coze host (including scheme and port)
|
||||||
COZE_HOST=http://nw.sgcode.cn:18888
|
COZE_HOST=http://localhost:8888
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ dotenv.config();
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 3010;
|
const port = 3010;
|
||||||
|
const cozeHost = (process.env.COZE_HOST || 'http://localhost:8888').replace(/\/+$/, '');
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
@@ -232,7 +233,7 @@ app.get('/api/coze/space-url', async (req, res) => {
|
|||||||
return;
|
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 });
|
res.json({ url, spaceId: space.id, user: user.email || user.unique_name || user.name });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Resolve Coze space URL failed:', 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 secret = process.env.SSO_SHARED_SECRET;
|
||||||
const cozeHost = process.env.COZE_HOST || 'http://nw.sgcode.cn:18888';
|
|
||||||
|
|
||||||
if (!secret) {
|
if (!secret) {
|
||||||
res.status(500).json({ message: 'SSO is not configured on server (missing SSO_SHARED_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 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
|
token
|
||||||
)}&next=${nextPath}`;
|
)}&next=${nextPath}`;
|
||||||
|
|
||||||
@@ -277,11 +277,13 @@ app.get('/api/coze/sso-login', (req, res) => {
|
|||||||
|
|
||||||
ensureUsersTable()
|
ensureUsersTable()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
console.log('Database initialization completed.');
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Failed to initialize database (server will still start):', error);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Auth API running at http://localhost:${port}`);
|
console.log(`Auth API running at http://localhost:${port}`);
|
||||||
});
|
});
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Failed to initialize database:', error);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user