add deno/bing.js

This commit is contained in:
James Feng Cao 2023-04-07 21:38:56 +08:00
parent 441db3a1f4
commit 6a726e893c
2 changed files with 25 additions and 1 deletions

View File

@ -84,7 +84,7 @@ The first part [rootDomain] is required and the others are optional. regex is ja
</div>
<p>Last Modified: 7 April 2023<br>
add cloudflare/bing.js<br>
add bing.js for cf &amp; deno<br>
<pre></pre>
</p>

24
en/searchurl/deno/bing.js Normal file
View File

@ -0,0 +1,24 @@
import { serve } from "https://deno.land/std@0.140.0/http/server.ts";
async function handler(req: Request): Promise<Response> {
let url = req.url;
let iSlash = url.indexOf('/',11);
let nUrl = "https://www.bing.com/"+url.substring(iSlash+1);
let fp = {
method: req.method,
headers: {}
}
let reqHeaders = new Headers(req.headers);
let keepHeaders = ["cookie","user-agent","accept","accept-language"];
let he = reqHeaders.entries();
for (let h of he) {
let key = h[0],
value = h[1];
if (keepHeaders.includes(key)) {
fp.headers[key] = value;
}
}
return await fetch(nUrl, fp);
}
serve(handler);