Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Bringing react engine in existing express app. #137

Open
reggi opened this issue Feb 4, 2016 · 2 comments
Open

Bringing react engine in existing express app. #137

reggi opened this issue Feb 4, 2016 · 2 comments

Comments

@reggi
Copy link
Contributor

reggi commented Feb 4, 2016

I'm trying to wrap all of react-engine and my small react app in a module that can easily be used in another larger express app for example if you export the app variable at the end of this file example/server.js and rename that file react-code.js then make another file server.js with something like this:

import reactCode from './react-code'
import express from 'express';
let app = express();

app.use(reactCode)

const PORT = 3000;

const server = app.listen(PORT, function() {
  console.log('Example app listening at http://localhost:%s', PORT);
});

I can easily move around the react piece in a larger express app (ignore that theres a * glob assigned to every route in the example).

The thing I'm having a more hard time including in this modularity is the webpack integration. I was wondering if it was possible to use webpack programmatically and given env flags a piece of middleware could render .bundle.js and serve it directly from express instead of having webpack render a file in a specific public folder. The fixed public folder, and the webpack script prevents a react-engine route / express app from being easily encapsulated.

Wondering general thoughts on this. I'm trying to compartmentalize / organize the react-engine-app portion of a greater app, without too much overhead on integrating webpack.

  • /packages
    • /react-engine-app
  • /app.js
@reggi reggi changed the title Encapsulation Bringing react engine in existing express app. Feb 4, 2016
@reggi
Copy link
Contributor Author

reggi commented Feb 12, 2016

I have a demo of how I'm encapsulating a the react-engine in this gist. I'm calling it react-engine-wrapper.js, could be useful to other people.

@samsel
Copy link
Contributor

samsel commented Mar 26, 2016

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants