@samselikoff wrote:
I’m working on a feature for Mirage, that will make some Mirage code available to Node so that it can be used in an Express middleware.
I’d like some advice on how best to write the Broccoli code.
At a high level, here’s my current thinking on what needs to happen:
- Read code from the host app’s
/mirage
directory, turn it from ES6 into CJS- Read code from Mirage’s source, turn it into CJS
require()
code from those places in theserverMiddleware()
hook, instantiate a new Mirage server with config from the host app, and go from thereI’m trying to start out with just #2 – ignoring the host app for now, and just getting the Mirage server code written to CJS in a place where I can
require()
it from theserverMiddleware()
hook.What’s the right way to think about this?
In my experimenting so far, I followed some other addons and used Rollup via
broccoli-rollup
to read inember-cli-mirage/addon/server.js
(which is sort of the entry point for Mirage), and wrote it to CJS.Where I’m getting confused is, where I can/should write this CJS file so that I can reliably “get” to it in
serverMiddleware()
.In general, since
serverMiddleware
doesn’t get a tree I feel confused about how that hook can interact with files created at build-time. I also sometimes reach for something like a.then
method on my broccoli trees, but don’t know if that’s possible or a recommended pattern. (In other words, once I write my CJS file, if I could.then()
andrequire()
it, I could throw some instance data ontothis
and access it like that fromserverMiddleware
. Feels hacky, but it could get me unstuck.)Any recommendations here? Really appreciate it!
Posts: 6
Participants: 2