@searchos/bot-proxy 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-VPK7GIYJ.js +2 -0
- package/dist/index.cjs +2 -1
- package/dist/index.js +1 -1
- package/dist/nextjs.cjs +2 -1
- package/dist/nextjs.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-NYRQ66HM.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{b as H,c as I,d as w}from"./chunk-BVZHYMX6.js";var P=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,L=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function B(t,o){let{projectId:e,cloudfrontDomain:f,renderDomain:s,botLogEndpoint:i,aiRender:R=!0,ocr:b=!0,aiPathPrefixes:$=[]}=o,c=o.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),S=f.replace(/\/$/,""),p=new URL(t.url),n=p.pathname;if(t.headers.get("x-prerender-host")){if(P.test(n)||n===`/${e}.txt`){let{NextResponse:a}=await import("next/server");return a.next()}return null}if(n===`/${e}.txt`)return new Response(e,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(P.test(n)){try{let a=await fetch(`${s}/static${n}`,{headers:{"X-Signature":e,"X-Original-Host":c}});if(a.ok)return new Response(a.body,{status:200,headers:{"Content-Type":a.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let g=t.headers.get("user-agent")||"",h=H(g);if(!h)return null;let v=L.test(g)?"mobile":"desktop",A=I(p.search),T=A?`${n}?${A}`:n,d=`https://${c}${T}`,m=W(t);console.log("[bot-proxy] req "+JSON.stringify({bot:h.name,isAi:h.isAi,path:n,clientIp:m,headers:{"user-agent":g,"x-forwarded-for":t.headers.get("x-forwarded-for"),"x-real-ip":t.headers.get("x-real-ip"),"x-forwarded-host":t.headers.get("x-forwarded-host"),"cf-connecting-ip":t.headers.get("cf-connecting-ip"),"cloudfront-viewer-address":t.headers.get("cloudfront-viewer-address"),"x-vercel-forwarded-for":t.headers.get("x-vercel-forwarded-for"),"x-amzn-trace-id":t.headers.get("x-amzn-trace-id"),"true-client-ip":t.headers.get("true-client-ip"),referer:t.headers.get("referer"),"accept-language":t.headers.get("accept-language"),host:t.headers.get("host")},headerKeys:Array.from(t.headers.keys())}));try{if(h.isAi&&R){let l=await w(T,"ai"),k=`${S}/v2/${c}/${l}.html`,u=null;try{u=await fetch(k,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf-ai "+JSON.stringify({status:u.status,ok:u.ok}))}catch(r){console.error("[bot-proxy] cf-ai THROW "+JSON.stringify({url:k,name:r?.name,msg:r?.message}))}if(u&&u.ok){let r="";try{r=await u.text()}catch(E){console.error("[bot-proxy] cf-ai TEXT-THROW "+JSON.stringify({msg:E?.message}))}if(console.log("[bot-proxy] cf-ai body "+JSON.stringify({length:r.length})),r&&r.length>100)return O(i,m,e,c,n,p.search,g,"hit_ai"),C(s,e,d,b,$),N(r,"HIT-AI",h.name)}let D=await w(T,"desktop"),j=`${S}/v2/${c}/${D}.html`,x=null;try{x=await fetch(j,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf-desktop-fallback "+JSON.stringify({status:x.status,ok:x.ok}))}catch(r){console.error("[bot-proxy] cf-desktop-fallback THROW "+JSON.stringify({url:j,name:r?.name,msg:r?.message}))}if(x&&x.ok){let r="";try{r=await x.text()}catch(E){console.error("[bot-proxy] cf-desktop-fallback TEXT-THROW "+JSON.stringify({msg:E?.message}))}if(console.log("[bot-proxy] cf-desktop-fallback body "+JSON.stringify({length:r.length})),r&&r.length>100)return O(i,m,e,c,n,p.search,g,"hit_desktop_fallback"),C(s,e,d,b,$),N(r,"HIT-DESKTOP",h.name)}return O(i,m,e,c,n,p.search,g,"miss_ai"),C(s,e,d,b,$),J(s,e,d),null}let a=await w(T,v),_=`${S}/v2/${c}/${a}.html`,y=null;try{y=await fetch(_,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf "+JSON.stringify({status:y.status,ok:y.ok}))}catch(l){console.error("[bot-proxy] cf THROW "+JSON.stringify({url:_,name:l?.name,msg:l?.message}))}if(y&&y.ok){let l="";try{l=await y.text()}catch(k){console.error("[bot-proxy] cf TEXT-THROW "+JSON.stringify({msg:k?.message}))}if(console.log("[bot-proxy] cf body "+JSON.stringify({length:l.length})),l&&l.length>100)return O(i,m,e,c,n,p.search,g,"hit"),J(s,e,d),N(l,"HIT",h.name)}}catch(a){console.error("[bot-proxy] OUTER-CATCH "+JSON.stringify({name:a?.name,msg:a?.message,stack:a?.stack?.split(`
|
|
2
|
+
`).slice(0,5).join(" | ")}))}return console.log("[bot-proxy] fallthrough-miss "+JSON.stringify({isAi:h.isAi})),O(i,m,e,c,n,p.search,g,"miss"),J(s,e,d),null}function N(t,o,e){return new Response(t,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":e}})}function W(t){let o=t.headers,e=o.get("x-forwarded-for")||"";return o.get("cf-connecting-ip")||o.get("x-real-ip")||e.split(",")[0].trim()||""}function O(t,o,e,f,s,i,R,b){fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:e,url:`https://${f}${s}${i}`,domain:f,path:s,user_agent:R,phase:b,client_ip:o})}).catch(()=>{})}function J(t,o,e){fetch(`${t}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:e,project_id:o}]})}).catch(()=>{})}function C(t,o,e,f,s){let i={items:[{url:e,project_id:o}],ocr:f};s.length>0&&(i.path_prefixes=s),fetch(`${t}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}export{B as a};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var et=Object.create;var P=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var st=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var at=(e,n)=>{for(var t in n)P(e,t,{get:n[t],enumerable:!0})},W=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of st(n))!ot.call(e,s)&&s!==t&&P(e,s,{get:()=>n[s],enumerable:!(r=nt(n,s))||r.enumerable});return e};var X=(e,n,t)=>(t=e!=null?et(rt(e)):{},W(n||!e||!e.__esModule?P(t,"default",{value:e,enumerable:!0}):t,e)),it=e=>W(P({},"__esModule",{value:!0}),e);var Ct={};at(Ct,{cloudflareProxy:()=>q,nextjsProxy:()=>Z});module.exports=it(Ct);var H=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],M=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],Q=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],z=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],G=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],ct=["uptimerobot","lighthouse","chrome-lighthouse"],J=new Set([...H,...M]),N=new Set(H),lt=[...H,...M,...Q,...z,...G,...ct];function j(e){let n=e.toLowerCase();for(let t of lt)if(n.includes(t)){let r;return N.has(t)?r="ai-user":J.has(t)?r="ai-crawl":Q.includes(t)?r="search":z.includes(t)?r="sns":G.includes(t)?r="seo":r="monitoring",{name:t,isAi:J.has(t),category:r}}return null}var pt=new Set(["utm_source","utm_medium","utm_campaign","utm_term","utm_content","fbclid","fb_action_ids","fb_action_types","fb_source","fb_ref","gclid","gclsrc","dclid","gbraid","wbraid","msclkid","hsa_cam","hsa_grp","hsa_mt","hsa_src","hsa_ad","hsa_acc","hsa_net","hsa_ver","hsa_la","hsa_ol","hsa_kw","_hsenc","_hsmi","_ga","_gl","_bhlid","mc_cid","mc_eid","oly_anon_id","oly_enc_id","ttclid","yclid","irclickid"]);function R(e){if(!e||(e.startsWith("?")&&(e=e.substring(1)),!e))return"";let n=[];for(let t of e.split("&")){if(!t)continue;let r=t.indexOf("="),s=r===-1?t:t.substring(0,r);pt.has(s.toLowerCase())||n.push(t)}return n.join("&")}function F(e){return encodeURIComponent(e).replace(/[!'()*]/g,n=>"%"+n.charCodeAt(0).toString(16).toUpperCase())}function ut(e){if(!e)return"/";let n,t,r=e.slice(0,8).toLowerCase();if(r.startsWith("http://")||r.startsWith("https://"))try{let o=new URL(e);n=o.pathname,t=o.search.startsWith("?")?o.search.substring(1):o.search}catch{n=e,t=""}else{let o=e.indexOf("?");o===-1?(n=e,t=""):(n=e.substring(0,o),t=e.substring(o+1))}n||(n="/");let s=n.split("/").map(o=>{if(!o)return o;try{return F(decodeURIComponent(o))}catch{return F(o)}}).join("/"),i=R(t);return i?`${s}?${i}`:s}async function gt(e){if(typeof process<"u"&&process.versions?.node){let{createHash:r}=await import("crypto");return r("md5").update(e,"utf8").digest("hex")}let n=new TextEncoder().encode(e),t=await crypto.subtle.digest("MD5",n);return Array.from(new Uint8Array(t),r=>r.toString(16).padStart(2,"0")).join("")}async function b(e,n){let t=ut(e);return`${await gt(t)}_${n}`}var Y=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,dt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function Z(e,n){let{projectId:t,cloudfrontDomain:r,renderDomain:s,botLogEndpoint:i,aiRender:o=!0,ocr:c=!0,aiPathPrefixes:$=[]}=n,l=n.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),C=r.replace(/\/$/,""),x=new URL(e.url),a=x.pathname;if(e.headers.get("x-prerender-host")){if(Y.test(a)||a===`/${t}.txt`){let{NextResponse:h}=await import("next/server");return h.next()}return null}if(a===`/${t}.txt`)return new Response(t,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(Y.test(a)){try{let h=await fetch(`${s}/static${a}`,{headers:{"X-Signature":t,"X-Original-Host":l}});if(h.ok)return new Response(h.body,{status:200,headers:{"Content-Type":h.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let p=e.headers.get("user-agent")||"",d=j(p);if(!d)return null;let g=dt.test(p)?"mobile":"desktop",O=R(x.search),E=O?`${a}?${O}`:a,y=`https://${l}${E}`,f=ht(e);try{if(d.isAi&&o){let _=await b(E,"ai"),u=await fetch(`${C}/v2/${l}/${_}.html`,{headers:{Accept:"text/html"}});if(u.ok){let w=await u.text();if(w&&w.length>100)return A(i,f,t,l,a,x.search,p,"hit_ai"),L(s,t,y,c,$),B(w,"HIT-AI",d.name)}let k=await b(E,"desktop"),I=await fetch(`${C}/v2/${l}/${k}.html`,{headers:{Accept:"text/html"}});if(I.ok){let w=await I.text();if(w&&w.length>100)return A(i,f,t,l,a,x.search,p,"hit_desktop_fallback"),L(s,t,y,c,$),B(w,"HIT-DESKTOP",d.name)}return A(i,f,t,l,a,x.search,p,"miss_ai"),L(s,t,y,c,$),K(s,t,y),null}let h=await b(E,g),T=await fetch(`${C}/v2/${l}/${h}.html`,{headers:{Accept:"text/html"}});if(T.ok){let _=await T.text();if(_&&_.length>100)return A(i,f,t,l,a,x.search,p,"hit"),K(s,t,y),B(_,"HIT",d.name)}}catch{}return A(i,f,t,l,a,x.search,p,"miss"),K(s,t,y),null}function B(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}function ht(e){let n=e.headers,t=n.get("x-forwarded-for")||"";return n.get("cf-connecting-ip")||n.get("x-real-ip")||t.split(",")[0].trim()||""}function A(e,n,t,r,s,i,o,c){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:t,url:`https://${r}${s}${i}`,domain:r,path:s,user_agent:o,phase:c,client_ip:n})}).catch(()=>{})}function K(e,n,t){fetch(`${e}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:n}]})}).catch(()=>{})}function L(e,n,t,r,s){let i={items:[{url:t,project_id:n}],ocr:r};s.length>0&&(i.path_prefixes=s),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}var ft=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,mt=/mobile|android|iphone|phone|tablet|webos|ipad/i,yt=604800;async function q(e,n,t,r){let{projectId:s,siteDomain:i,renderDomain:o,botLogEndpoint:c,aiRender:$=!0,ocr:l=!0,aiPathPrefixes:C=[]}=r,x=new URL(e.url),a=x.pathname,p=i.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(e.method==="POST"){if(a==="/__update-edge-cache")return bt(e,n);if(a==="/__purge-edge-cache")return xt(e,n);if(a==="/__read-edge-cache")return wt(e,n)}if(e.headers.get("x-prerender-host"))return null;if(a===`/${s}.txt`)try{let u=await fetch(`${o}${a}`,{redirect:"manual"});return new Response(u.body,{status:u.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(ft.test(a))try{let u=await fetch(`${o}/static${a}`,{redirect:"manual",headers:{"X-Signature":s,"X-Original-Host":p}});return new Response(u.body,{status:u.status,headers:{"Content-Type":u.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let d=e.headers.get("user-agent")||"",g=j(d);if(!g||!n.V2_CACHE)return null;let O=mt.test(d)?"mobile":"desktop",E=R(x.search),y=E?`${a}?${E}`:a,f=`https://${p}${y}`,h=N.has(g.name)?"ai-user":g.isAi?"ai-crawl":"standard",T=_t(e),_=u=>t.waitUntil(u().catch(k=>console.error("[bot-proxy]",k)));try{if(g.isAi&&$){let I=await b(y,"ai"),w=await n.V2_CACHE.get(I);if(w)return _(async()=>{console.log(`[BOT] ${g.name} | ${h} | hit_ai | ${a}`),await S(c,T,s,p,a,d,"hit_ai"),await U(o,s,f,l,C)}),V(w,"HIT-AI",g.name);let tt=await b(y,"desktop"),D=await n.V2_CACHE.get(tt);return D?(_(async()=>{console.log(`[BOT] ${g.name} | ${h} | hit_desktop_fallback | ${a}`),await S(c,T,s,p,a,d,"hit_desktop_fallback"),await U(o,s,f,l,C)}),V(D,"HIT-DESKTOP",g.name)):(_(async()=>{console.log(`[BOT] ${g.name} | ${h} | miss_ai | ${a}`),await S(c,T,s,p,a,d,"miss_ai"),await Promise.all([U(o,s,f,l,C),v(o,s,f)])}),null)}let u=await b(y,O),k=await n.V2_CACHE.get(u);return k?(_(async()=>{console.log(`[BOT] ${g.name} | ${h} | hit | ${a}`),await S(c,T,s,p,a,d,"hit"),await v(o,s,f)}),V(k,"HIT",g.name)):(_(async()=>{console.log(`[BOT] ${g.name} | ${h} | miss | ${a}`),await S(c,T,s,p,a,d,"miss"),await v(o,s,f)}),null)}catch(u){return console.error("[bot-proxy]",u),null}}function V(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}function _t(e){let n=e.headers;return n.get("cf-connecting-ip")||n.get("x-real-ip")||(n.get("x-forwarded-for")||"").split(",")[0].trim()||""}async function S(e,n,t,r,s,i,o){await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:t,url:`https://${r}${s}`,domain:r,path:s,user_agent:i,phase:o,client_ip:n})})}async function v(e,n,t){await fetch(`${e}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:n}]})})}function m(e,n=200){return new Response(JSON.stringify(e),{status:n,headers:{"Content-Type":"application/json"}})}async function bt(e,n){try{let{entries:t=[]}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t.length)return m({success:!1,error:"entries \uD544\uC218"},400);let r=0;for(let s of t){let{url:i,html:o,variant:c="",device:$="desktop"}=s||{};if(!i||!o)continue;let l=c.startsWith("v2_")?c.substring(3):$,C=await b(i,l);await n.V2_CACHE.put(C,o,{expirationTtl:yt}),r++}return m({success:!0,updated:r})}catch(t){return m({success:!1,error:t.message},500)}}async function xt(e,n){try{let{urls:t=[],variant:r=""}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t.length)return m({success:!1,error:"urls \uD544\uC218"},400);let s=r.startsWith("v2_")?r.substring(3):"desktop",i=0;for(let o of t){let c=await b(o,s);await n.V2_CACHE.delete(c),i++}return m({success:!0,deleted:i})}catch(t){return m({success:!1,error:t.message},500)}}async function wt(e,n){try{let{url:t,variant:r=""}=await e.json();if(!n.V2_CACHE)return m({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!t)return m({success:!1,error:"url \uD544\uC218"},400);let s=r.startsWith("v2_")?r.substring(3):"desktop",i=await b(t,s),o=await n.V2_CACHE.get(i);return m({success:!0,html:o??null})}catch(t){return m({success:!1,error:t.message},500)}}async function U(e,n,t,r,s){let i={items:[{url:t,project_id:n}],ocr:r};s.length>0&&(i.path_prefixes=s),await fetch(`${e}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}0&&(module.exports={cloudflareProxy,nextjsProxy});
|
|
1
|
+
"use strict";var st=Object.create;var P=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,it=Object.prototype.hasOwnProperty;var ct=(t,r)=>{for(var e in r)P(t,e,{get:r[e],enumerable:!0})},z=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of ot(r))!it.call(t,s)&&s!==e&&P(t,s,{get:()=>r[s],enumerable:!(n=nt(r,s))||n.enumerable});return t};var M=(t,r,e)=>(e=t!=null?st(at(t)):{},z(r||!t||!t.__esModule?P(e,"default",{value:t,enumerable:!0}):e,t)),lt=t=>z(P({},"__esModule",{value:!0}),t);var kt={};ct(kt,{cloudflareProxy:()=>rt,nextjsProxy:()=>et});module.exports=lt(kt);var K=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],G=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],F=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],Y=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],Z=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],pt=["uptimerobot","lighthouse","chrome-lighthouse"],Q=new Set([...K,...G]),J=new Set(K),gt=[...K,...G,...F,...Y,...Z,...pt];function B(t){let r=t.toLowerCase();for(let e of gt)if(r.includes(e)){let n;return J.has(e)?n="ai-user":Q.has(e)?n="ai-crawl":F.includes(e)?n="search":Y.includes(e)?n="sns":Z.includes(e)?n="seo":n="monitoring",{name:e,isAi:Q.has(e),category:n}}return null}var dt=new Set(["utm_source","utm_medium","utm_campaign","utm_term","utm_content","fbclid","fb_action_ids","fb_action_types","fb_source","fb_ref","gclid","gclsrc","dclid","gbraid","wbraid","msclkid","hsa_cam","hsa_grp","hsa_mt","hsa_src","hsa_ad","hsa_acc","hsa_net","hsa_ver","hsa_la","hsa_ol","hsa_kw","_hsenc","_hsmi","_ga","_gl","_bhlid","mc_cid","mc_eid","oly_anon_id","oly_enc_id","ttclid","yclid","irclickid"]);function $(t){if(!t||(t.startsWith("?")&&(t=t.substring(1)),!t))return"";let r=[];for(let e of t.split("&")){if(!e)continue;let n=e.indexOf("="),s=n===-1?e:e.substring(0,n);dt.has(s.toLowerCase())||r.push(e)}return r.join("&")}function q(t){return encodeURIComponent(t).replace(/[!'()*]/g,r=>"%"+r.charCodeAt(0).toString(16).toUpperCase())}function ht(t){if(!t)return"/";let r,e,n=t.slice(0,8).toLowerCase();if(n.startsWith("http://")||n.startsWith("https://"))try{let o=new URL(t);r=o.pathname,e=o.search.startsWith("?")?o.search.substring(1):o.search}catch{r=t,e=""}else{let o=t.indexOf("?");o===-1?(r=t,e=""):(r=t.substring(0,o),e=t.substring(o+1))}r||(r="/");let s=r.split("/").map(o=>{if(!o)return o;try{return q(decodeURIComponent(o))}catch{return q(o)}}).join("/"),i=$(e);return i?`${s}?${i}`:s}async function ut(t){if(typeof process<"u"&&process.versions?.node){let{createHash:n}=await import("crypto");return n("md5").update(t,"utf8").digest("hex")}let r=new TextEncoder().encode(t),e=await crypto.subtle.digest("MD5",r);return Array.from(new Uint8Array(e),n=>n.toString(16).padStart(2,"0")).join("")}async function _(t,r){let e=ht(t);return`${await ut(e)}_${r}`}var tt=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,ft=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function et(t,r){let{projectId:e,cloudfrontDomain:n,renderDomain:s,botLogEndpoint:i,aiRender:o=!0,ocr:g=!0,aiPathPrefixes:R=[]}=r,d=r.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),C=n.replace(/\/$/,""),w=new URL(t.url),a=w.pathname;if(t.headers.get("x-prerender-host")){if(tt.test(a)||a===`/${e}.txt`){let{NextResponse:l}=await import("next/server");return l.next()}return null}if(a===`/${e}.txt`)return new Response(e,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(tt.test(a)){try{let l=await fetch(`${s}/static${a}`,{headers:{"X-Signature":e,"X-Original-Host":d}});if(l.ok)return new Response(l.body,{status:200,headers:{"Content-Type":l.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let h=t.headers.get("user-agent")||"",u=B(h);if(!u)return null;let f=ft.test(h)?"mobile":"desktop",I=$(w.search),S=I?`${a}?${I}`:a,b=`https://${d}${S}`,m=mt(t);console.log("[bot-proxy] req "+JSON.stringify({bot:u.name,isAi:u.isAi,path:a,clientIp:m,headers:{"user-agent":h,"x-forwarded-for":t.headers.get("x-forwarded-for"),"x-real-ip":t.headers.get("x-real-ip"),"x-forwarded-host":t.headers.get("x-forwarded-host"),"cf-connecting-ip":t.headers.get("cf-connecting-ip"),"cloudfront-viewer-address":t.headers.get("cloudfront-viewer-address"),"x-vercel-forwarded-for":t.headers.get("x-vercel-forwarded-for"),"x-amzn-trace-id":t.headers.get("x-amzn-trace-id"),"true-client-ip":t.headers.get("true-client-ip"),referer:t.headers.get("referer"),"accept-language":t.headers.get("accept-language"),host:t.headers.get("host")},headerKeys:Array.from(t.headers.keys())}));try{if(u.isAi&&o){let c=await _(S,"ai"),T=`${C}/v2/${d}/${c}.html`,O=null;try{O=await fetch(T,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf-ai "+JSON.stringify({status:O.status,ok:O.ok}))}catch(p){console.error("[bot-proxy] cf-ai THROW "+JSON.stringify({url:T,name:p?.name,msg:p?.message}))}if(O&&O.ok){let p="";try{p=await O.text()}catch(v){console.error("[bot-proxy] cf-ai TEXT-THROW "+JSON.stringify({msg:v?.message}))}if(console.log("[bot-proxy] cf-ai body "+JSON.stringify({length:p.length})),p&&p.length>100)return A(i,m,e,d,a,w.search,h,"hit_ai"),V(s,e,b,g,R),L(p,"HIT-AI",u.name)}let H=await _(S,"desktop"),j=`${C}/v2/${d}/${H}.html`,k=null;try{k=await fetch(j,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf-desktop-fallback "+JSON.stringify({status:k.status,ok:k.ok}))}catch(p){console.error("[bot-proxy] cf-desktop-fallback THROW "+JSON.stringify({url:j,name:p?.name,msg:p?.message}))}if(k&&k.ok){let p="";try{p=await k.text()}catch(v){console.error("[bot-proxy] cf-desktop-fallback TEXT-THROW "+JSON.stringify({msg:v?.message}))}if(console.log("[bot-proxy] cf-desktop-fallback body "+JSON.stringify({length:p.length})),p&&p.length>100)return A(i,m,e,d,a,w.search,h,"hit_desktop_fallback"),V(s,e,b,g,R),L(p,"HIT-DESKTOP",u.name)}return A(i,m,e,d,a,w.search,h,"miss_ai"),V(s,e,b,g,R),U(s,e,b),null}let l=await _(S,f),E=`${C}/v2/${d}/${l}.html`,y=null;try{y=await fetch(E,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf "+JSON.stringify({status:y.status,ok:y.ok}))}catch(c){console.error("[bot-proxy] cf THROW "+JSON.stringify({url:E,name:c?.name,msg:c?.message}))}if(y&&y.ok){let c="";try{c=await y.text()}catch(T){console.error("[bot-proxy] cf TEXT-THROW "+JSON.stringify({msg:T?.message}))}if(console.log("[bot-proxy] cf body "+JSON.stringify({length:c.length})),c&&c.length>100)return A(i,m,e,d,a,w.search,h,"hit"),U(s,e,b),L(c,"HIT",u.name)}}catch(l){console.error("[bot-proxy] OUTER-CATCH "+JSON.stringify({name:l?.name,msg:l?.message,stack:l?.stack?.split(`
|
|
2
|
+
`).slice(0,5).join(" | ")}))}return console.log("[bot-proxy] fallthrough-miss "+JSON.stringify({isAi:u.isAi})),A(i,m,e,d,a,w.search,h,"miss"),U(s,e,b),null}function L(t,r,e){return new Response(t,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":r,"X-Bot":e}})}function mt(t){let r=t.headers,e=r.get("x-forwarded-for")||"";return r.get("cf-connecting-ip")||r.get("x-real-ip")||e.split(",")[0].trim()||""}function A(t,r,e,n,s,i,o,g){fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:e,url:`https://${n}${s}${i}`,domain:n,path:s,user_agent:o,phase:g,client_ip:r})}).catch(()=>{})}function U(t,r,e){fetch(`${t}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:e,project_id:r}]})}).catch(()=>{})}function V(t,r,e,n,s){let i={items:[{url:e,project_id:r}],ocr:n};s.length>0&&(i.path_prefixes=s),fetch(`${t}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}var yt=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,xt=/mobile|android|iphone|phone|tablet|webos|ipad/i,bt=604800;async function rt(t,r,e,n){let{projectId:s,siteDomain:i,renderDomain:o,botLogEndpoint:g,aiRender:R=!0,ocr:d=!0,aiPathPrefixes:C=[]}=n,w=new URL(t.url),a=w.pathname,h=i.replace(/^https?:\/\//,"").replace(/\/+$/,"");if(t.method==="POST"){if(a==="/__update-edge-cache")return wt(t,r);if(a==="/__purge-edge-cache")return Ct(t,r);if(a==="/__read-edge-cache")return Tt(t,r)}if(t.headers.get("x-prerender-host"))return null;if(a===`/${s}.txt`)try{let c=await fetch(`${o}${a}`,{redirect:"manual"});return new Response(c.body,{status:c.status,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return new Response("",{status:404})}if(yt.test(a))try{let c=await fetch(`${o}/static${a}`,{redirect:"manual",headers:{"X-Signature":s,"X-Original-Host":h}});return new Response(c.body,{status:c.status,headers:{"Content-Type":c.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{return null}let u=t.headers.get("user-agent")||"",f=B(u);if(!f||!r.V2_CACHE)return null;let I=xt.test(u)?"mobile":"desktop",S=$(w.search),b=S?`${a}?${S}`:a,m=`https://${h}${b}`,l=J.has(f.name)?"ai-user":f.isAi?"ai-crawl":"standard",E=_t(t),y=c=>e.waitUntil(c().catch(T=>console.error("[bot-proxy]",T)));try{if(f.isAi&&R){let O=await _(b,"ai"),H=await r.V2_CACHE.get(O);if(H)return y(async()=>{console.log(`[BOT] ${f.name} | ${l} | hit_ai | ${a}`),await N(g,E,s,h,a,u,"hit_ai"),await X(o,s,m,d,C)}),W(H,"HIT-AI",f.name);let j=await _(b,"desktop"),k=await r.V2_CACHE.get(j);return k?(y(async()=>{console.log(`[BOT] ${f.name} | ${l} | hit_desktop_fallback | ${a}`),await N(g,E,s,h,a,u,"hit_desktop_fallback"),await X(o,s,m,d,C)}),W(k,"HIT-DESKTOP",f.name)):(y(async()=>{console.log(`[BOT] ${f.name} | ${l} | miss_ai | ${a}`),await N(g,E,s,h,a,u,"miss_ai"),await Promise.all([X(o,s,m,d,C),D(o,s,m)])}),null)}let c=await _(b,I),T=await r.V2_CACHE.get(c);return T?(y(async()=>{console.log(`[BOT] ${f.name} | ${l} | hit | ${a}`),await N(g,E,s,h,a,u,"hit"),await D(o,s,m)}),W(T,"HIT",f.name)):(y(async()=>{console.log(`[BOT] ${f.name} | ${l} | miss | ${a}`),await N(g,E,s,h,a,u,"miss"),await D(o,s,m)}),null)}catch(c){return console.error("[bot-proxy]",c),null}}function W(t,r,e){return new Response(t,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":r,"X-Bot":e}})}function _t(t){let r=t.headers;return r.get("cf-connecting-ip")||r.get("x-real-ip")||(r.get("x-forwarded-for")||"").split(",")[0].trim()||""}async function N(t,r,e,n,s,i,o){await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:e,url:`https://${n}${s}`,domain:n,path:s,user_agent:i,phase:o,client_ip:r})})}async function D(t,r,e){await fetch(`${t}/v2/cache/kv`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:e,project_id:r}]})})}function x(t,r=200){return new Response(JSON.stringify(t),{status:r,headers:{"Content-Type":"application/json"}})}async function wt(t,r){try{let{entries:e=[]}=await t.json();if(!r.V2_CACHE)return x({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e.length)return x({success:!1,error:"entries \uD544\uC218"},400);let n=0;for(let s of e){let{url:i,html:o,variant:g="",device:R="desktop"}=s||{};if(!i||!o)continue;let d=g.startsWith("v2_")?g.substring(3):R,C=await _(i,d);await r.V2_CACHE.put(C,o,{expirationTtl:bt}),n++}return x({success:!0,updated:n})}catch(e){return x({success:!1,error:e.message},500)}}async function Ct(t,r){try{let{urls:e=[],variant:n=""}=await t.json();if(!r.V2_CACHE)return x({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e.length)return x({success:!1,error:"urls \uD544\uC218"},400);let s=n.startsWith("v2_")?n.substring(3):"desktop",i=0;for(let o of e){let g=await _(o,s);await r.V2_CACHE.delete(g),i++}return x({success:!0,deleted:i})}catch(e){return x({success:!1,error:e.message},500)}}async function Tt(t,r){try{let{url:e,variant:n=""}=await t.json();if(!r.V2_CACHE)return x({success:!1,error:"V2_CACHE \uBC14\uC778\uB529 \uC5C6\uC74C"},500);if(!e)return x({success:!1,error:"url \uD544\uC218"},400);let s=n.startsWith("v2_")?n.substring(3):"desktop",i=await _(e,s),o=await r.V2_CACHE.get(i);return x({success:!0,html:o??null})}catch(e){return x({success:!1,error:e.message},500)}}async function X(t,r,e,n,s){let i={items:[{url:e,project_id:r}],ocr:n};s.length>0&&(i.path_prefixes=s),await fetch(`${t}/v2/cache/kv/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})}0&&(module.exports={cloudflareProxy,nextjsProxy});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-WERE2ZTC.js";import{a as r}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-WERE2ZTC.js";import{a as r}from"./chunk-VPK7GIYJ.js";import"./chunk-BVZHYMX6.js";export{o as cloudflareProxy,r as nextjsProxy};
|
package/dist/nextjs.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var V=Object.create;var S=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var et=(t,o)=>{for(var e in o)S(t,e,{get:o[e],enumerable:!0})},K=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of Z(o))!tt.call(t,s)&&s!==e&&S(t,s,{get:()=>o[s],enumerable:!(r=Y(o,s))||r.enumerable});return t};var L=(t,o,e)=>(e=t!=null?V(q(t)):{},K(o||!t||!t.__esModule?S(e,"default",{value:t,enumerable:!0}):e,t)),ot=t=>K(S({},"__esModule",{value:!0}),t);var pt={};et(pt,{nextjsProxy:()=>G});module.exports=ot(pt);var $=["chatgpt-user","claude-user","perplexity-user","gemini-user","gemini-deep-research","mistralai-user","grok-user"],U=["gptbot","oai-searchbot","claudebot","claude-searchbot","google-extended","google-cloudvertexbot","perplexitybot","meta-externalagent","applebot-extended","amazonbot","cohere-ai","bytespider","deepseekbot","grokbot","ccbot","diffbot","ai2bot","petalbot"],H=["googlebot","googlebot-image","googlebot-video","googlebot-news","googleother","mediapartners-google","adsbot-google","google-inspectiontool","bingbot","bingpreview","naverbot","yeti","daumoa","baiduspider","yandexbot","duckduckbot","applebot"],W=["facebookexternalhit","linkedinbot","twitterbot","slackbot","discordbot","telegrambot","whatsapp","pinterestbot","redditbot"],D=["ahrefsbot","semrushbot","mj12bot","dotbot","dataforseobot"],rt=["uptimerobot","lighthouse","chrome-lighthouse"],P=new Set([...$,...U]),st=new Set($),nt=[...$,...U,...H,...W,...D,...rt];function X(t){let o=t.toLowerCase();for(let e of nt)if(o.includes(e)){let r;return st.has(e)?r="ai-user":P.has(e)?r="ai-crawl":H.includes(e)?r="search":W.includes(e)?r="sns":D.includes(e)?r="seo":r="monitoring",{name:e,isAi:P.has(e),category:r}}return null}var at=new Set(["utm_source","utm_medium","utm_campaign","utm_term","utm_content","fbclid","fb_action_ids","fb_action_types","fb_source","fb_ref","gclid","gclsrc","dclid","gbraid","wbraid","msclkid","hsa_cam","hsa_grp","hsa_mt","hsa_src","hsa_ad","hsa_acc","hsa_net","hsa_ver","hsa_la","hsa_ol","hsa_kw","_hsenc","_hsmi","_ga","_gl","_bhlid","mc_cid","mc_eid","oly_anon_id","oly_enc_id","ttclid","yclid","irclickid"]);function k(t){if(!t||(t.startsWith("?")&&(t=t.substring(1)),!t))return"";let o=[];for(let e of t.split("&")){if(!e)continue;let r=e.indexOf("="),s=r===-1?e:e.substring(0,r);at.has(s.toLowerCase())||o.push(e)}return o.join("&")}function z(t){return encodeURIComponent(t).replace(/[!'()*]/g,o=>"%"+o.charCodeAt(0).toString(16).toUpperCase())}function it(t){if(!t)return"/";let o,e,r=t.slice(0,8).toLowerCase();if(r.startsWith("http://")||r.startsWith("https://"))try{let n=new URL(t);o=n.pathname,e=n.search.startsWith("?")?n.search.substring(1):n.search}catch{o=t,e=""}else{let n=t.indexOf("?");n===-1?(o=t,e=""):(o=t.substring(0,n),e=t.substring(n+1))}o||(o="/");let s=o.split("/").map(n=>{if(!n)return n;try{return z(decodeURIComponent(n))}catch{return z(n)}}).join("/"),i=k(e);return i?`${s}?${i}`:s}async function ct(t){if(typeof process<"u"&&process.versions?.node){let{createHash:r}=await import("crypto");return r("md5").update(t,"utf8").digest("hex")}let o=new TextEncoder().encode(t),e=await crypto.subtle.digest("MD5",o);return Array.from(new Uint8Array(e),r=>r.toString(16).padStart(2,"0")).join("")}async function E(t,o){let e=it(t);return`${await ct(e)}_${o}`}var M=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,lt=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function G(t,o){let{projectId:e,cloudfrontDomain:r,renderDomain:s,botLogEndpoint:i,aiRender:n=!0,ocr:_=!0,aiPathPrefixes:R=[]}=o,g=o.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),N=r.replace(/\/$/,""),f=new URL(t.url),c=f.pathname;if(t.headers.get("x-prerender-host")){if(M.test(c)||c===`/${e}.txt`){let{NextResponse:l}=await import("next/server");return l.next()}return null}if(c===`/${e}.txt`)return new Response(e,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(M.test(c)){try{let l=await fetch(`${s}/static${c}`,{headers:{"X-Signature":e,"X-Original-Host":g}});if(l.ok)return new Response(l.body,{status:200,headers:{"Content-Type":l.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let d=t.headers.get("user-agent")||"",h=X(d);if(!h)return null;let Q=lt.test(d)?"mobile":"desktop",B=k(f.search),w=B?`${c}?${B}`:c,m=`https://${g}${w}`,u=gt(t);console.log("[bot-proxy] req "+JSON.stringify({bot:h.name,isAi:h.isAi,path:c,clientIp:u,headers:{"user-agent":d,"x-forwarded-for":t.headers.get("x-forwarded-for"),"x-real-ip":t.headers.get("x-real-ip"),"x-forwarded-host":t.headers.get("x-forwarded-host"),"cf-connecting-ip":t.headers.get("cf-connecting-ip"),"cloudfront-viewer-address":t.headers.get("cloudfront-viewer-address"),"x-vercel-forwarded-for":t.headers.get("x-vercel-forwarded-for"),"x-amzn-trace-id":t.headers.get("x-amzn-trace-id"),"true-client-ip":t.headers.get("true-client-ip"),referer:t.headers.get("referer"),"accept-language":t.headers.get("accept-language"),host:t.headers.get("host")},headerKeys:Array.from(t.headers.keys())}));try{if(h.isAi&&n){let p=await E(w,"ai"),O=`${N}/v2/${g}/${p}.html`,b=null;try{b=await fetch(O,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf-ai "+JSON.stringify({status:b.status,ok:b.ok}))}catch(a){console.error("[bot-proxy] cf-ai THROW "+JSON.stringify({url:O,name:a?.name,msg:a?.message}))}if(b&&b.ok){let a="";try{a=await b.text()}catch(C){console.error("[bot-proxy] cf-ai TEXT-THROW "+JSON.stringify({msg:C?.message}))}if(console.log("[bot-proxy] cf-ai body "+JSON.stringify({length:a.length})),a&&a.length>100)return T(i,u,e,g,c,f.search,d,"hit_ai"),j(s,e,m,_,R),A(a,"HIT-AI",h.name)}let F=await E(w,"desktop"),v=`${N}/v2/${g}/${F}.html`,x=null;try{x=await fetch(v,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf-desktop-fallback "+JSON.stringify({status:x.status,ok:x.ok}))}catch(a){console.error("[bot-proxy] cf-desktop-fallback THROW "+JSON.stringify({url:v,name:a?.name,msg:a?.message}))}if(x&&x.ok){let a="";try{a=await x.text()}catch(C){console.error("[bot-proxy] cf-desktop-fallback TEXT-THROW "+JSON.stringify({msg:C?.message}))}if(console.log("[bot-proxy] cf-desktop-fallback body "+JSON.stringify({length:a.length})),a&&a.length>100)return T(i,u,e,g,c,f.search,d,"hit_desktop_fallback"),j(s,e,m,_,R),A(a,"HIT-DESKTOP",h.name)}return T(i,u,e,g,c,f.search,d,"miss_ai"),j(s,e,m,_,R),I(s,e,m),null}let l=await E(w,Q),J=`${N}/v2/${g}/${l}.html`,y=null;try{y=await fetch(J,{headers:{Accept:"text/html"}}),console.log("[bot-proxy] cf "+JSON.stringify({status:y.status,ok:y.ok}))}catch(p){console.error("[bot-proxy] cf THROW "+JSON.stringify({url:J,name:p?.name,msg:p?.message}))}if(y&&y.ok){let p="";try{p=await y.text()}catch(O){console.error("[bot-proxy] cf TEXT-THROW "+JSON.stringify({msg:O?.message}))}if(console.log("[bot-proxy] cf body "+JSON.stringify({length:p.length})),p&&p.length>100)return T(i,u,e,g,c,f.search,d,"hit"),I(s,e,m),A(p,"HIT",h.name)}}catch(l){console.error("[bot-proxy] OUTER-CATCH "+JSON.stringify({name:l?.name,msg:l?.message,stack:l?.stack?.split(`
|
|
2
|
+
`).slice(0,5).join(" | ")}))}return console.log("[bot-proxy] fallthrough-miss "+JSON.stringify({isAi:h.isAi})),T(i,u,e,g,c,f.search,d,"miss"),I(s,e,m),null}function A(t,o,e){return new Response(t,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":o,"X-Bot":e}})}function gt(t){let o=t.headers,e=o.get("x-forwarded-for")||"";return o.get("cf-connecting-ip")||o.get("x-real-ip")||e.split(",")[0].trim()||""}function T(t,o,e,r,s,i,n,_){fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:e,url:`https://${r}${s}${i}`,domain:r,path:s,user_agent:n,phase:_,client_ip:o})}).catch(()=>{})}function I(t,o,e){fetch(`${t}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:e,project_id:o}]})}).catch(()=>{})}function j(t,o,e,r,s){let i={items:[{url:e,project_id:o}],ocr:r};s.length>0&&(i.path_prefixes=s),fetch(`${t}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}0&&(module.exports={nextjsProxy});
|
package/dist/nextjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-
|
|
1
|
+
import{a as o}from"./chunk-VPK7GIYJ.js";import"./chunk-BVZHYMX6.js";export{o as nextjsProxy};
|
package/package.json
CHANGED
package/dist/chunk-NYRQ66HM.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as P,c as S,d as $}from"./chunk-BVZHYMX6.js";var A=/^\/(?:robots\.txt|llms\.txt|sitemap[^\/]*\.(?:xml|xsl))$/i,L=/mobile|android|iphone|phone|tablet|webos|ipad/i;async function H(e,n){let{projectId:t,cloudfrontDomain:l,renderDomain:s,botLogEndpoint:i,aiRender:w=!0,ocr:g=!0,aiPathPrefixes:b=[]}=n,o=n.siteDomain.replace(/^https?:\/\//,"").replace(/\/+$/,""),T=l.replace(/\/$/,""),a=new URL(e.url),r=a.pathname;if(e.headers.get("x-prerender-host")){if(A.test(r)||r===`/${t}.txt`){let{NextResponse:h}=await import("next/server");return h.next()}return null}if(r===`/${t}.txt`)return new Response(t,{status:200,headers:{"Content-Type":"text/plain","Cache-Control":"public, max-age=3600"}});if(A.test(r)){try{let h=await fetch(`${s}/static${r}`,{headers:{"X-Signature":t,"X-Original-Host":o}});if(h.ok)return new Response(h.body,{status:200,headers:{"Content-Type":h.headers.get("Content-Type")||"text/plain","Cache-Control":"public, max-age=3600"}})}catch{}return null}let c=e.headers.get("user-agent")||"",m=P(c);if(!m)return null;let D=L.test(c)?"mobile":"desktop",j=S(a.search),y=j?`${r}?${j}`:r,d=`https://${o}${y}`,u=v(e);try{if(m.isAi&&w){let f=await $(y,"ai"),I=await fetch(`${T}/v2/${o}/${f}.html`,{headers:{Accept:"text/html"}});if(I.ok){let p=await I.text();if(p&&p.length>100)return x(i,u,t,o,r,a.search,c,"hit_ai"),_(s,t,d,g,b),R(p,"HIT-AI",m.name)}let E=await $(y,"desktop"),O=await fetch(`${T}/v2/${o}/${E}.html`,{headers:{Accept:"text/html"}});if(O.ok){let p=await O.text();if(p&&p.length>100)return x(i,u,t,o,r,a.search,c,"hit_desktop_fallback"),_(s,t,d,g,b),R(p,"HIT-DESKTOP",m.name)}return x(i,u,t,o,r,a.search,c,"miss_ai"),_(s,t,d,g,b),C(s,t,d),null}let h=await $(y,D),k=await fetch(`${T}/v2/${o}/${h}.html`,{headers:{Accept:"text/html"}});if(k.ok){let f=await k.text();if(f&&f.length>100)return x(i,u,t,o,r,a.search,c,"hit"),C(s,t,d),R(f,"HIT",m.name)}}catch{}return x(i,u,t,o,r,a.search,c,"miss"),C(s,t,d),null}function R(e,n,t){return new Response(e,{headers:{"Content-Type":"text/html; charset=utf-8","X-Cache":n,"X-Bot":t}})}function v(e){let n=e.headers,t=n.get("x-forwarded-for")||"";return n.get("cf-connecting-ip")||n.get("x-real-ip")||t.split(",")[0].trim()||""}function x(e,n,t,l,s,i,w,g){fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project_id:t,url:`https://${l}${s}${i}`,domain:l,path:s,user_agent:w,phase:g,client_ip:n})}).catch(()=>{})}function C(e,n,t){fetch(`${e}/v2/cache`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{url:t,project_id:n}]})}).catch(()=>{})}function _(e,n,t,l,s){let i={items:[{url:t,project_id:n}],ocr:l};s.length>0&&(i.path_prefixes=s),fetch(`${e}/v2/cache/ai`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)}).catch(()=>{})}export{H as a};
|