├── README.md ├── worker.js └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # disqusjs-proxy-cloudflare-workers 2 | 3 | proxy disqus api via cloudflare workers 4 | 5 | demo: [https://disqus.emiria.moe/api/](https://disqus.emiria.moe/api/) && [https://disqus.dawn.workers.dev/api/](https://disqus.dawn.workers.dev/api/) 6 | 7 | (此项目基于 CVM 开发模式,显然我完全不会 JavaScript 8 | 9 | # Cloudflare Workers 路由示例 10 | 11 | `https://disqus.emiria.moe/api/*` -> `this worker` 12 | -------------------------------------------------------------------------------- /worker.js: -------------------------------------------------------------------------------- 1 | addEventListener('fetch', event => { 2 | event.respondWith(proxy(event)); 3 | }); 4 | 5 | async function proxy(event) { 6 | const getReqHeader = (key) => event.request.headers.get(key); 7 | 8 | let url = new URL(event.request.url); 9 | url.hostname = "disqus.com"; 10 | 11 | let parameter = { 12 | headers: { 13 | 'Host': 'disqus.com', 14 | 'User-Agent': getReqHeader("User-Agent"), 15 | 'Accept': getReqHeader("Accept"), 16 | 'Accept-Language': getReqHeader("Accept-Language"), 17 | 'Accept-Encoding': getReqHeader("Accept-Encoding"), 18 | 'Connection': 'keep-alive', 19 | 'Cache-Control': 'max-age=0' 20 | } 21 | }; 22 | 23 | if (event.request.headers.has("Referer")) { 24 | parameter.headers.Referer = getReqHeader("Referer"); 25 | } 26 | 27 | if (event.request.headers.has("Origin")) { 28 | parameter.headers.Origin = getReqHeader("Origin"); 29 | } 30 | 31 | return fetch(new Request(url, event.request), parameter); 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | --------------------------------------------------------------------------------