import Cors from "cors" ; const cors = Cors ( { methods : [ "GET" , "HEAD" ] , } ) ; function runMiddleware ( req , res , fn ) { return new Promise ( ( resolve , reject ) => { fn ( req , res , ( result ) => { if ( result instanceof Error ) { return reject ( result ) ; } return resolve ( result ) ; } ) ; } ) ; } export default async function uploadHandler ( req , res ) { await runMiddleware ( req , res , cors ) ; const { method } = req ; switch ( method ) { case "POST" : try { } catch ( e ) { res . statusCode = 500 ; console . error ( "Request error" , e ) ; res . json ( { error : "Error creating upload" } ) ; } break ; default : res . setHeader ( "Allow" , [ "POST" ] ) ; res . status ( 405 ) . end ( `Method ${ method } Not Allowed` ) ; } }