UNPKG

cdk-nextjs

Version:

Deploy Next.js apps on AWS with CDK

2 lines (1 loc) 2.41 kB
"use strict";(()=>{var R=Object.defineProperty;var b=(o,t,e)=>t in o?R(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var u=(o,t,e)=>b(o,typeof t!="symbol"?t+"":t,e);var f=window.fetch,L=window.XMLHttpRequest;window.fetch=async function(t,e){var y;if(!e)return f(t,e);let s=(y=e.method)==null?void 0:y.toUpperCase();if(s!=="PUT"&&s!=="POST")return f(t,e);let r;if(typeof t=="string"?r=new URL(t,window.location.href):t instanceof URL?r=t:t instanceof Request?r=new URL(t.url,window.location.href):r=new URL(String(t),window.location.href),r.hostname!==window.location.hostname)return f(t,e);let n=e.body,a,l=new Headers(e.headers);if(n)if(typeof n=="string")a=n;else if(n instanceof FormData){let c="----FormBoundary"+Math.random().toString(16).slice(2);a=A(c,n),l.set("content-type","multipart/form-data; boundary=".concat(c)),e.body=a}else if(n instanceof URLSearchParams)a=n.toString();else if(n instanceof Blob)a=await n.text();else if(n instanceof ArrayBuffer)a=new Uint8Array(n);else if(ArrayBuffer.isView(n))a=new Uint8Array(n.buffer,n.byteOffset,n.byteLength);else if(n instanceof ReadableStream){let c=n.getReader(),h=[],m=!1;for(;!m;){let{value:i,done:w}=await c.read();m=w,i&&h.push(i)}let U=h.reduce((i,w)=>i+w.length,0),d=new Uint8Array(U),g=0;for(let i of h)d.set(i,g),g+=i.length;a=d,e.body=d}else a=JSON.stringify(n);else a="";let S=await p(a);return l.set("x-amz-content-sha256",S),e.headers=l,f(t,e)};window.XMLHttpRequest=class extends L{constructor(){super();u(this,"method","");u(this,"url","");this.originalOpen=super.open,this.originalSend=super.send,super.open=(e,s,...r)=>{this.method=e.toUpperCase(),this.url=s,this.originalOpen.apply(this,[e,s,...r])},super.send=async e=>{if((this.method==="PUT"||this.method==="POST")&&new URL(this.url,window.location.href).hostname===window.location.hostname&&e){let s=typeof e=="string"?e:JSON.stringify(e),r=await p(s);this.setRequestHeader("x-amz-content-sha256",r)}this.originalSend.apply(this,[e])}}};async function p(o){let t;o instanceof Uint8Array?t=o:t=new TextEncoder().encode(o);let e=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(e)).map(s=>s.toString(16).padStart(2,"0")).join("")}function A(o,t){let e="";for(let[s,r]of t.entries())e+="--".concat(o,"\r\n"),e+='Content-Disposition: form-data; name="'.concat(s,'"\r\n'),e+="\r\n",e+="".concat(r,"\r\n");return e+="--".concat(o,"--"),e}})();