@@ -17,12 +17,9 @@ export interface Env {
17
17
18
18
export default {
19
19
async fetch ( request : Request , env : Env , ctx : ExecutionContext ) : Promise < Response > {
20
- if ( ! env . REWRITE_HOSTNAME ) throw new Error ( "Missing REWRITE_HOSTNAME" ) ;
21
- console . log ( "url" , request . url ) ;
22
-
23
20
if ( ! queueingIsEnabled ( env ) ) {
24
21
console . log ( "Missing AWS credentials. Passing through to the origin." ) ;
25
- return redirectToOrigin ( request , env ) ;
22
+ return fetch ( request ) ;
26
23
}
27
24
28
25
const url = new URL ( request . url ) ;
@@ -42,25 +39,10 @@ export default {
42
39
}
43
40
44
41
//the same request but with the hostname (and port) changed
45
- return redirectToOrigin ( request , env ) ;
42
+ return fetch ( request ) ;
46
43
} ,
47
44
} ;
48
45
49
- function redirectToOrigin ( request : Request , env : Env ) {
50
- const newUrl = new URL ( request . url ) ;
51
- newUrl . hostname = env . REWRITE_HOSTNAME ;
52
- newUrl . port = env . REWRITE_PORT || newUrl . port ;
53
-
54
- const requestInit : RequestInit = {
55
- method : request . method ,
56
- headers : request . headers ,
57
- body : request . body ,
58
- } ;
59
-
60
- console . log ( "rewritten url" , newUrl . toString ( ) ) ;
61
- return fetch ( newUrl . toString ( ) , requestInit ) ;
62
- }
63
-
64
46
function queueingIsEnabled ( env : Env ) {
65
47
return (
66
48
env . AWS_SQS_ACCESS_KEY_ID &&
0 commit comments