carteb / carte-blanche

An isolated development space with integrated fuzz testing for your components. See them individually, explore them in different states and quickly and confidently develop them.
https://www.youtube.com/watch?v=6g3-TQ6aaw8
MIT License
1.5k stars 47 forks source link

Add Express.js support #295

Closed mxstbr closed 8 years ago

mxstbr commented 8 years ago

What we do under the hood is emitting a new asset from webpack at carte-blanche/index.html. (or whatever you specify in the dest option) This means that if you're using express.js for routing, users will never find the Carte Blanche because express.js sends back a 404.

We should be exposing an easy-to-use route which redirects to Carte Blanche. I've never done this before, so maybe there's a better way, but this seems like the nicest solution at the moment:

import { carteBlancheRoute } from 'carte-blanche';
/* … */
app.get('/carte-blanche/', carteBlancheRoute);
ericclemmons commented 8 years ago

Hi! It sounds like this overlaps with the request I have:

It sounds like this is possible, based on the internals I took a cursory look at.

Is this issue for the same feature?

mxstbr commented 8 years ago

Is this issue for the same feature?

Not entirely sure from your explanation, what exactly do you mean with "but would want to "embed" it within the app."?

Currently you can change the route from localhost:3000/carte-blanche to localhost:3000/components, but I'm not entirely sure that satisfies your use case.

nikgraf commented 8 years ago

@mxstbr I think we should write a carteBlancheMiddleware like webpackDevMiddleware or webpackHotMiddleware. If people initialize it like that: app.use(carteBlancheMiddleware(compiler)) we can check check for the path and emit the right file. I think it's important to use a middleware, because then we also can emit the client, user-bundle and other assets we might need in the future.

Here some resources:

nikgraf commented 8 years ago

The code to submit the assets as of now: https://github.com/carteb/carte-blanche/blob/master/webpack-plugin/src/apply.js#L64

grabbou commented 8 years ago

@mxstbr sounds like an issue for me (again) 😆

ericclemmons commented 8 years ago

Sorry I wasn't clear. @nikgraf's recommendation for carteBlancheMiddleware is what I was inquiring about. (I have an existing Express server running that I'd like to have serve /components from Carte Blanche from within the same instance).

The nice thing about middleware is you can remove the path option by doing:

app.use("/components", cartBlancheMiddleware(compiler))

Anyway, I'll be testing the project out this week & hopefully be able to help. <subscribed>

mxstbr commented 8 years ago

& hopefully be able to help

That's what we love to hear!

I've pushed up a first (not yet working) express.js example to the express-integration branch—as soon as that's actually working you'll be able to run it with npm run example:express.

mxstbr commented 8 years ago

Done with v0.2! :tada: