{"id":55778,"date":"2025-02-19T14:19:05","date_gmt":"2025-02-19T06:19:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/55778\/"},"modified":"2025-02-19T14:19:05","modified_gmt":"2025-02-19T06:19:05","slug":"%e4%bd%bf%e7%94%a8deno%e4%b8%ba%e4%bb%bb%e6%84%8f%e5%a4%a7%e6%a8%a1%e5%9e%8b%e5%ae%89%e5%85%a8%e7%9a%84%e4%bb%a3%e7%90%86api%ef%bc%8c%e9%81%bf%e5%85%8d%e6%b3%84%e9%9c%b2%e7%9c%9f%e5%ae%9eip%e5%92%8c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/55778\/","title":{"rendered":"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f"},"content":{"rendered":"<p>\u89e3\u51b3\u67d0\u4e9b\u5730\u533a\u65e0\u6cd5\u76f4\u63a5\u8bf7\u6c42api.openai.com\u7b49\u7b49\u5927\u6a21\u578bAPI\uff0c\u6216\u8005\u56e0\u4e3a\u4ee3\u7406\u6cc4\u9732\u4fe1\u606f\u5bfc\u81f4\u5c01\u5e10\u53f7\uff0c\u4e4b\u524d\u4f7f\u7528CF\u4ee3\u7406\uff0c\u53ef\u80fd\u4f1a\u6cc4\u9732\u4f60\u7684IP\uff0c\u73b0\u5728\u6709\u4e00\u4e2a\u8f83\u4e3a\u5b89\u5168\u7684\u65b9\u6848\u3002<\/p>\n<p><strong>1.\u9996\u5148\u8fdb\u5165deno\u5b98\u7f51\u6ce8\u518c\u8d26\u53f7<\/strong><\/p>\n<p> <\/p>\n<p><strong>2.\u521b\u5efa\u9879\u76ee<\/strong><\/p>\n<p>\u8bbf\u95ee https:\/\/dash.deno.com\/account\/projects\uff0c\u70b9\u51fb\u201cNew Playground\u201d<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.aisharenet.com\/wp-content\/uploads\/2024\/12\/393fe4e20434cba.png\" title=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe\" alt=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>3.\u7c98\u8d34\u4ee3\u7801\u5e76\u4fdd\u5b58<\/strong><\/p>\n<pre>import { serve } from \"https:\/\/deno.land\/std\/http\/server.ts\";\r\n\nconst apiMapping = {\r\n'\/discord': 'https:\/\/discord.com\/api',\r\n'\/telegram': 'https:\/\/api.telegram.org',\r\n'\/openai': 'https:\/\/api.openai.com',\r\n'\/claude': 'https:\/\/api.anthropic.com',\r\n'\/gemini': 'https:\/\/generativelanguage.googleapis.com',\r\n'\/meta': 'https:\/\/www.meta.ai\/api',\r\n'\/groq': 'https:\/\/api.groq.com\/openai',\r\n'\/xai': 'https:\/\/api.x.ai',\r\n'\/cohere': 'https:\/\/api.cohere.ai',\r\n'\/huggingface': 'https:\/\/api-inference.huggingface.co',\r\n'\/together': 'https:\/\/api.together.xyz',\r\n'\/novita': 'https:\/\/api.novita.ai',\r\n'\/portkey': 'https:\/\/api.portkey.ai',\r\n'\/fireworks': 'https:\/\/api.fireworks.ai',\r\n'\/openrouter': 'https:\/\/openrouter.ai\/api'\r\n};\r\n\nserve(async (request) =&gt; {\r\nconst url = new URL(request.url);\r\nconst pathname = url.pathname;\r\n\nif (pathname === '\/' || pathname === '\/index.html') {\r\nreturn new Response('Service is running!', {\r\nstatus: 200,\r\nheaders: { 'Content-Type': 'text\/html' }\r\n});\r\n} \r\n\nif (pathname === '\/robots.txt') {\r\nreturn new Response('User-agent: *\\nDisallow: \/', {\r\nstatus: 200,\r\nheaders: { 'Content-Type': 'text\/plain' }\r\n});\r\n}\r\n\nconst [prefix, rest] = extractPrefixAndRest(pathname, Object.keys(apiMapping));\r\nif (!prefix) {\r\nreturn new Response('Not Found', { status: 404 });\r\n}\r\n\nconst targetUrl = `${apiMapping[prefix]}${rest}`;\r\n\ntry {\r\nconst headers = new Headers();\r\nconst allowedHeaders = ['accept', 'content-type', 'authorization'];\r\nfor (const [key, value] of request.headers.entries()) {\r\nif (allowedHeaders.includes(key.toLowerCase())) {\r\nheaders.set(key, value);\r\n}\r\n}\r\n\nconst response = await fetch(targetUrl, {\r\nmethod: request.method,\r\nheaders: headers,\r\nbody: request.body\r\n});\r\n\nconst responseHeaders = new Headers(response.headers);\r\nresponseHeaders.set('X-Content-Type-Options', 'nosniff');\r\nresponseHeaders.set('X-Frame-Options', 'DENY');\r\nresponseHeaders.set('Referrer-Policy', 'no-referrer');\r\n\nreturn new Response(response.body, {\r\nstatus: response.status,\r\nheaders: responseHeaders\r\n});\r\n\n} catch (error) {\r\nconsole.error('Failed to fetch:', error);\r\nreturn new Response('Internal Server Error', { status: 500 });\r\n}\r\n});\r\n\nfunction extractPrefixAndRest(pathname, prefixes) {\r\nfor (const prefix of prefixes) {\r\nif (pathname.startsWith(prefix)) {\r\nreturn [prefix, pathname.slice(prefix.length)];\r\n}\r\n}\r\nreturn [null, null];\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%201073%20635'%3E%3C\/svg%3E\" title=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe1\" alt=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe1\" \/> <img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.aisharenet.com\/wp-content\/uploads\/2024\/12\/d8beac4da94d95b.png\" title=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe2\" alt=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe2\" \/> <\/p>\n<p>&nbsp;<\/p>\n<p><strong>4.\u4f7f\u7528\u65b9\u6cd5<\/strong><\/p>\n<p>\u9ed8\u8ba4\u57df\u540d\u662f https:\/\/hungry-lamb-22.deno.dev\/<\/p>\n<p>\u8bbf\u95ee<code>https:\/\/hungry-lamb-22.deno.dev\/xai<\/code> \u7b49\u4e8e\u8bbf\u95ee <code>https:\/\/api.x.ai\/<\/code><\/p>\n<p>\u6309\u7167\u4ee3\u7801\u91cc\u7684\u683c\u5f0f\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u65b0\u7684\u5927\u6a21\u578b\u8bf7\u6c42\u5730\u5740<\/p>\n<p>&nbsp;<\/p>\n<p><strong>5.\u81ea\u5b9a\u4e49\u57df\u540d<\/strong><\/p>\n<p>\u8fdb\u5165\u8bbe\u7f6e\uff0c\u7ed1\u5b9a\u4f60\u81ea\u5df1\u7684\u57df\u540d<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%20627%20350'%3E%3C\/svg%3E\" title=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe3\" alt=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe3\" \/> <img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.aisharenet.com\/wp-content\/uploads\/2024\/12\/adaf026ec3341d4.png\" title=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe4\" alt=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe4\" \/> <\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u5171\u4eab\u4ee3\u7406\u5730\u5740<\/strong> <\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" align=\"right\" src=\"\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%20150%20150'%3E%3C\/svg%3E\" style=\"width:150px;height:150px;margin-left:20px;border:none\" title=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe5\" alt=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe5\" \/><br \/>\n<img decoding=\"async\" class=\"aligncenter\" align=\"right\" src=\"https:\/\/www.aisharenet.com\/wp-content\/uploads\/2024\/07\/99dd797026b75ad.jpg\" style=\"width:150px;height:150px;margin-left:20px;border:none\" title=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe6\" alt=\"\u4f7f\u7528deno\u4e3a\u4efb\u610f\u5927\u6a21\u578b\u5b89\u5168\u7684\u4ee3\u7406API\uff0c\u907f\u514d\u6cc4\u9732\u771f\u5b9eIP\u548c\u57df\u540d\u4fe1\u606f\u63d2\u56fe6\" \/><br \/>\n<span style=\"font-size:18px\">\u6b64\u5904\u5185\u5bb9\u5df2\u7ecf\u88ab\u4f5c\u8005\u9690\u85cf\uff0c\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801\u67e5\u770b\u5185\u5bb9<\/span><br \/>\n<span style=\"font-size:18px;float:left\">\u9a8c\u8bc1\u7801\uff1a<\/span><br \/>\n<span style=\"color:#00BF30\">\u8bf7\u5173\u6ce8\u672c\u7ad9\u5fae\u4fe1\u516c\u4f17\u53f7\uff0c\u56de\u590d\u201c<span style=\"color:blue\">\u9a8c\u8bc1\u7801<\/span>\u201d\uff0c\u83b7\u53d6\u9a8c\u8bc1\u7801\u3002\u5728\u5fae\u4fe1\u91cc\u641c\u7d22\u201c<span style=\"color:blue\">\u9996\u5e2dAI\u5206\u4eab\u5708<\/span>\u201d\u6216\u8005\u201c<span style=\"color:blue\">Looks-AI<\/span>\u201d\u6216\u8005\u5fae\u4fe1\u626b\u63cf\u53f3\u4fa7\u4e8c\u7ef4\u7801\u90fd\u53ef\u4ee5\u5173\u6ce8\u672c\u7ad9\u5fae\u4fe1\u516c\u4f17\u53f7\u3002<\/span> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3\u67d0\u4e9b\u5730\u533a\u65e0\u6cd5\u76f4\u63a5\u8bf7\u6c42api.openai.com\u7b49\u7b49\u5927\u6a21\u578bAPI\uff0c\u6216\u8005\u56e0\u4e3a\u4ee3\u7406\u6cc4\u9732\u4fe1\u606f\u5bfc\u81f4\u5c01\u5e10\u53f7\uff0c\u4e4b\u524d\u4f7f\u7528CF\u4ee3\u7406\uff0c\u53ef\u80fd\u4f1a\u6cc4\u9732\u4f60\u7684IP\uff0c\u73b0\u5728\u6709\u4e00\u4e2a\u8f83\u4e3a\u5b89\u5168\u7684\u65b9\u6848\u3002 1.\u9996\u5148\u8fdb\u5165deno\u5b98\u7f51\u6ce8\u518c\u8d26\u53f7 2.\u521b\u5efa\u9879\u76ee \u8bbf\u95ee https:\/\/dash.deno.com\/account\/projects\uff0c\u70b9\u51fb\u201cNew Playground\u201d &nbsp; 3.\u7c98\u8d34\u4ee3\u7801\u5e76\u4fdd\u5b58 import { serve } from &#8220;https:\/\/deno.land\/std\/http\/server.ts&#8221;; const apiMapping = { &#8216;\/discord&#8217;: &#8216;https:\/\/discord.com\/api&#8217;, &#8216;\/telegram&#8217;: &#8216;https:\/\/api.telegram.org&#8217;, &#8216;\/openai&#8217;: &#8216;https:\/\/api.openai.com&#8217;, &#8216;\/claude&#8217;: &#8216;https:\/\/api.anthropic.com&#8217;, &#8216;\/gemini&#8217;: &#8216;https:\/\/generativelanguage.googleapis.com&#8217;, &#8216;\/meta&#8217;: &#8216;https:\/\/www.meta.ai\/api&#8217;, &#8216;\/groq&#8217;: &#8216;https:\/\/api.groq.com\/openai&#8217;, &#8216;\/xai&#8217;: &#8216;https:\/\/api.x.ai&#8217;, &#8216;\/cohere&#8217;: &#8216;https:\/\/api.cohere.ai&#8217;, &#8216;\/huggingface&#8217;: &#8216;https:\/\/api-inference.huggingface.co&#8217;, &#8216;\/together&#8217;: &#8216;https:\/\/api.together.xyz&#8217;, &#8216;\/novita&#8217;: &#8216;https:\/\/api.novita.ai&#8217;, &#8216;\/portkey&#8217;: &#8216;https:\/\/api.portkey.ai&#8217;, &#8216;\/fireworks&#8217;: &#8216;https:\/\/api.fireworks.ai&#8217;, &#8216;\/openrouter&#8217;: &#8216;https:\/\/openrouter.ai\/api&#8217; }; serve(async (request) =&gt; { const url [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-55778","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/55778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=55778"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/55778\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=55778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=55778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=55778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}