(request, env = {})
| 2 | |
| 3 | const handlers = { |
| 4 | async fetch(request, env = {}) { |
| 5 | const uri = new URL(request.url) |
| 6 | console.log('uri', uri.toString()) |
| 7 | if (uri.protocol === 'http:' && !/^[0-9.:]+$/.test(TARGET_HOST)) { |
| 8 | uri.protocol = 'https:'; |
| 9 | } |
| 10 | uri.host = TARGET_HOST |
| 11 | uri.port = TARGET_HOST.split(':')[1] || '' |
| 12 | const headersObj = {} |
| 13 | for (const [key, value] of request.headers.entries()) { |
| 14 | if (key.startsWith('cf-') || key.startsWith('x-') || ['connection', 'origin', 'referer', 'host', 'authority', 'link'].includes(key)) continue |
| 15 | headersObj[key] = value |
| 16 | } |
| 17 | const headers = new Headers(headersObj) |
| 18 | headers.set('Host', uri.host) |
| 19 | // console.log(headers) |
| 20 | const response = await fetch(uri.toString(), { |
| 21 | headers, |
| 22 | method: request.method, |
| 23 | redirect: request.redirect, |
| 24 | body: request.body, |
| 25 | }) |
| 26 | return response |
| 27 | }, |
| 28 | } |
| 29 | |
| 30 | export default handlers |
no outgoing calls
no test coverage detected