Sdm0 commited on
Commit
c09fbc9
·
verified ·
1 Parent(s): 142b8a4

Deploy d9390596

Browse files
frontend/api/provider-test.js CHANGED
@@ -17,7 +17,9 @@ export default async function handler(req, res) {
17
  body = {model,max_tokens:256,messages:[{role:'user',content:prompt}]};
18
  } else {
19
  const base = new URL(baseUrl || 'https://api.openai.com/v1');
20
- if (base.protocol !== 'https:' || !['openrouter.ai','api.openai.com','api.groq.com','api.deepseek.com','tokenharbor.ai'].includes(base.hostname) || base.port || base.username || base.password) return res.status(400).json({error:'Use an HTTPS API URL from OpenRouter, OpenAI, Groq, DeepSeek, or TokenHarbor.'});
 
 
21
  url = `${base.origin}${base.pathname.replace(/\/$/,'')}/chat/completions`;
22
  headers = {Authorization:`Bearer ${apiKey}`};
23
  body = {model,max_tokens:256,messages:[{role:'user',content:prompt}]};
 
17
  body = {model,max_tokens:256,messages:[{role:'user',content:prompt}]};
18
  } else {
19
  const base = new URL(baseUrl || 'https://api.openai.com/v1');
20
+ const allowedHost = ['openrouter.ai','api.openai.com','api.groq.com','api.deepseek.com','tokenharbor.ai'].includes(base.hostname)
21
+ || base.hostname === 'trycloudflare.com' || base.hostname.endsWith('.trycloudflare.com');
22
+ if (base.protocol !== 'https:' || !allowedHost || base.port || base.username || base.password) return res.status(400).json({error:'Use an HTTPS API URL from OpenRouter, OpenAI, Groq, DeepSeek, TokenHarbor, or a Cloudflare trycloudflare.com tunnel.'});
23
  url = `${base.origin}${base.pathname.replace(/\/$/,'')}/chat/completions`;
24
  headers = {Authorization:`Bearer ${apiKey}`};
25
  body = {model,max_tokens:256,messages:[{role:'user',content:prompt}]};
frontend/api/provider-test.test.js CHANGED
@@ -60,3 +60,16 @@ test('TokenHarbor OpenAI-compatible URL is allowed', async () => {
60
  await handler(req,res); assert.equal(res.code,200); assert.equal(res.body.json_object_valid,true);
61
  } finally { globalThis.fetch = original; }
62
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  await handler(req,res); assert.equal(res.code,200); assert.equal(res.body.json_object_valid,true);
61
  } finally { globalThis.fetch = original; }
62
  });
63
+
64
+ test('Cloudflare temporary HTTPS tunnel is allowed for testing', async () => {
65
+ const original = globalThis.fetch;
66
+ try {
67
+ globalThis.fetch = async (url) => {
68
+ assert.equal(url, 'https://mapping-relates-mediterranean-cosmetic.trycloudflare.com/v1/chat/completions');
69
+ return {ok:true,json:async()=>({choices:[{message:{content:'{"findings":[]}'}}]})};
70
+ };
71
+ const req = request(), res = response();
72
+ req.body.baseUrl='https://mapping-relates-mediterranean-cosmetic.trycloudflare.com/v1';
73
+ await handler(req,res); assert.equal(res.code,200); assert.equal(res.body.json_object_valid,true);
74
+ } finally { globalThis.fetch=original; }
75
+ });