feat(server): 添加对OPTIONS请求的支持
处理跨域OPTIONS预检请求,返回200状态码和成功响应
This commit is contained in:
parent
ea0e49f568
commit
c762f8cf11
1 changed files with 6 additions and 1 deletions
|
|
@ -488,6 +488,11 @@ async function requestHandler(req, res) {
|
||||||
console.log(`\n[Server] Received request: ${req.method} http://${req.headers.host}${req.url}`);
|
console.log(`\n[Server] Received request: ${req.method} http://${req.headers.host}${req.url}`);
|
||||||
|
|
||||||
const requestUrl = new URL(req.url, `http://${req.headers.host}`);
|
const requestUrl = new URL(req.url, `http://${req.headers.host}`);
|
||||||
|
if (req.method === 'OPTIONS'){
|
||||||
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
|
console.log("OPTIONS REQUEST SUCCESS");
|
||||||
|
return res.end("OPTIONS REQUEST SUCCESS");
|
||||||
|
}
|
||||||
|
|
||||||
if (!isAuthorized(req, requestUrl)) {
|
if (!isAuthorized(req, requestUrl)) {
|
||||||
res.writeHead(401, { 'Content-Type': 'application/json' });
|
res.writeHead(401, { 'Content-Type': 'application/json' });
|
||||||
|
|
@ -496,7 +501,7 @@ async function requestHandler(req, res) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const service = await getApiService();
|
const service = await getApiService();
|
||||||
|
|
||||||
if (req.method === 'GET' && requestUrl.pathname === '/v1/models') {
|
if (req.method === 'GET' && requestUrl.pathname === '/v1/models') {
|
||||||
const models = await service.listModels();
|
const models = await service.listModels();
|
||||||
const openAIModels = toOpenAIModelList(models.models.map(m => m.name.replace('models/', '')));
|
const openAIModels = toOpenAIModelList(models.models.map(m => m.name.replace('models/', '')));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue