Skip to content

Commit

Permalink
修复options请求问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fatwang2 committed Jan 21, 2024
1 parent 4beb101 commit 4ef3ab0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ module.exports = async (req, res) => {
}
const apiBase = process.env.APIBASE || 'https://api.openai.com';
const authHeader = req.headers['authorization']; // 从请求的 headers 中获取 Authorization

let apiKey = '';
if (authHeader) {
apiKey = authHeader.split(' ')[1]; // 从 Authorization 中获取 API key
} else {
res.statusCode = 400;
res.end('Authorization header is missing');
return;
}

if (req.method === 'OPTIONS') {
const optionsResponse = handleOptions();
res.statusCode = optionsResponse.status;
Expand All @@ -82,6 +72,16 @@ module.exports = async (req, res) => {
res.end();
return;
}
let apiKey = '';
if (authHeader) {
apiKey = authHeader.split(' ')[1]; // 从 Authorization 中获取 API key
} else {
res.statusCode = 400;
res.end('Authorization header is missing');
return;
}



let response;
try {
Expand Down

0 comments on commit 4ef3ab0

Please sign in to comment.