Skip to content

Commit bced1cb

Browse files
committed
Fix: Strip quotes and whitespace from AUTH_KEY
- Remove leading/trailing quotes from AUTH_KEY - Trim whitespace from AUTH_KEY and ALLOWED_ORIGINS - Add detailed startup logging for debugging - Show full AUTH_KEY in logs for troubleshooting
1 parent 2fb9746 commit bced1cb

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const httpServer = createServer(app);
1515

1616
// 配置
1717
const PORT = parseInt(process.env.PORT || '3001', 10);
18-
const AUTH_KEY = process.env.AUTH_KEY || '';
19-
const ALLOWED_ORIGINS = process.env.ALLOWED_ORIGINS?.split(',') || ['*'];
18+
// 去除可能的引号和空格
19+
const AUTH_KEY = (process.env.AUTH_KEY || '').trim().replace(/^["']|["']$/g, '');
20+
const ALLOWED_ORIGINS = process.env.ALLOWED_ORIGINS?.split(',').map(o => o.trim()) || ['*'];
2021
const NODE_ENV = process.env.NODE_ENV || 'development';
2122

2223
// 验证必需的环境变量
@@ -127,7 +128,10 @@ httpServer.listen(PORT, () => {
127128
console.log('='.repeat(60));
128129
console.log(`Environment: ${NODE_ENV}`);
129130
console.log(`Port: ${PORT}`);
130-
console.log(`Auth Key: ${AUTH_KEY.substring(0, 8)}...`);
131+
console.log(`Auth Key (first 8 chars): ${AUTH_KEY.substring(0, 8)}...`);
132+
console.log(`Auth Key (last 8 chars): ...${AUTH_KEY.substring(AUTH_KEY.length - 8)}`);
133+
console.log(`Auth Key Length: ${AUTH_KEY.length}`);
134+
console.log(`Full Auth Key (for debugging): ${AUTH_KEY}`);
131135
console.log(`Allowed Origins: ${ALLOWED_ORIGINS.join(', ')}`);
132136
console.log('='.repeat(60));
133137
console.log(`Health Check: http://localhost:${PORT}/health`);

0 commit comments

Comments
 (0)