Open ImPeekaboo opened 11 months ago
after reading this blog post that announced support for ES modules..
off-hand, I see 3 minor issues:
get_middleware
would need to be made from a new entry point, which defines the params
objectmiddleware.request
method would need to be called from within the serverless fetch
method.. and its parameters (ie: req
and res
) would need to be mocked in such a way that input data from Request
is made available to the code.. and output data written to res
is ultimately output through a new Response
objectat a higher level:
le shrug..
to summarize:
it probably wouldn't be very difficult to make a few changes that:
require
statements to use ES import
syntaxparams.hooks
params.cache_segments
require
to a top-level import
import {params} from './cf-worker-params.js'
import {get_middleware} from './hls-proxy/proxy.js'
const middleware = get_middleware(params)
export default { async fetch(request, environment, context) { // https://developers.cloudflare.com/workers/runtime-apis/request // https://developers.cloudflare.com/workers/runtime-apis/response const response = new Response()
// minimal mock for: https://nodejs.org/api/http.html#class-httpclientrequest
const req = {
url: request.url,
headers: request.headers,
//...
}
// minimal mock for: https://nodejs.org/api/http.html#class-httpserverresponse
// to do: migrate API input data to the `response` object
const res = {
writeHead: ()=>{},
end: ()=>{},
//...
}
await middleware.request(req, res)
return response
} }
interesting rant.. which pretty much echoes my opinion exactly
it mentions something that I wasn't aware of..
maybe it was added later (after I'd already made up my mind about ES modules)..
which is that there exists an import()
statement to allow dynamic imports..
asinine..
but would make the rewrite from CommonJs much easier.
I see. Thank you for your humble response!
Thanks for your project, this is so useful. Is it possible to make this work on cloudflare workers?