Comments (18)
I am doing proxy using proxy-middleware. Modified srcServer.js
// This file configures the development web server
// which supports hot reloading and synchronized testing.
// Require Browsersync along with webpack and middleware for it
import browserSync from 'browser-sync';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import url from 'url';
import proxy from 'proxy-middleware';
import webpackConfigBuilder from '../webpack.config';
const webpackConfig = webpackConfigBuilder('development');
const bundler = webpack(webpackConfig);
var proxyOptions = url.parse('http://myproxyserver.net);
proxyOptions.route = '/api';
// Run Browsersync and use middleware for Hot Module Replacement
browserSync({
server: {
baseDir: 'src',
middleware: [
webpackDevMiddleware(bundler, {
// Dev middleware can't access config, so we provide publicPath
publicPath: webpackConfig.output.publicPath,
// pretty colored output
stats: { colors: true },
// Set to false to display a list of each file that is being bundled.
noInfo: true
// for other settings see
// http://webpack.github.io/docs/webpack-dev-middleware.html
}),
// bundler should be the same as above
webpackHotMiddleware(bundler),
proxy(proxyOptions)
]
},
// no need to watch '.js' here, webpack will take care of it for us,
// including full page reloads if HMR won't work
files: [
'src/.html'
]
});
from react-slingshot.
I'm reopening since I'd love to see a PR on this. :)
from react-slingshot.
Closing. Discussion further in the PR #93
from react-slingshot.
@kwelch You're a man on a mission tonight! Love it! 💯
from react-slingshot.
I saw this tweet from @mjackson and got very inspired.
from react-slingshot.
Great question. Can you point me to a working configuration example?
from react-slingshot.
@coryhouse I assume you're asking for an example in webpack-dev-server. Have a look at this file in one of my repos:
https://github.com/prpatel/react-workshop-day1/blob/master/Lab12/webpack.config.js
from react-slingshot.
So to be clear, this is an alternative to enabling CORS on local APIs, right? I suspect it's possible to pull this off along with browser-sync, but I haven't had time to hunt for an example yet.
from react-slingshot.
Actually, it is more about a seamless development experience / setup than CORS. Allow me to elaborate. I'm running my Rails/Node/Java/Python/etc backend server and want to create a SPA using React. During development, I need to either do one of these things to make this work:
- use ENV vars to set the base URL to my backend API server
- use magic vars (let authUrl = "http://localhost:3000";) that are managed using (1) or some other method
- Proxy API calls with some simple configuration through browsersync+webpack in this project's setup
IMO, (3) is not the easest, but is the most simple. From the research I've done into this, I think the answer may be to invert the browsersync+webpack setup:
https://www.npmjs.com/package/browser-sync-webpack-plugin
but I'm not a browersync expert, and haven't had time to dig into its guts to determine how this is possible - was hoping that someone here had already tackled this and had a quick answer.
from react-slingshot.
@prpatel did you find a solution for this? Mind sharing it here?
from react-slingshot.
The solution posted by @vssathish above works well.
from react-slingshot.
I am unable to push my branch. Do i need special permissions?
from react-slingshot.
@vssathish You don't need any special permissions to submit a pull request.
from react-slingshot.
Submitted a PR.
from react-slingshot.
@vssathish in this sample does your '../webpack.config' look identical to the OP? I do not see a 'webpack.config' in the root directory of the project only the webpack.config.dev and webpack.config.prod
from react-slingshot.
@frankbaum the changes are only to srcServer.js
from react-slingshot.
@vssathish I see your fork of the project - perhaps there was a change and new config files were added after you forked it - as there is not a webpack.config in the existing source there is a .dev and .prod version - thanks
from react-slingshot.
@vssathish, I'm a new collaborator on the project and am just going through the issues. Just wondering if you have any blockers to submit your PR?
from react-slingshot.
Related Issues (20)
- Use redux-saga
- npm run remove-demo doesn't work
- Terminal font becomes invisible after npm start
- Error running 'npm install' HOT 1
- Switch Redux logic setup to use Redux Toolkit HOT 4
- Involving Database HOT 4
- why there are yarn.lock and package-lock.json both present? HOT 6
- Implementation of redux-persist with react-slingshot HOT 5
- [WARNING] Removing the demo app also removes files that do not belong to the demo app
- Get error when execute "npm start" command. HOT 1
- Required Information about peripheral files. HOT 2
- Update README about python version HOT 1
- Refused to execute inline script because it violates the following Content Security Policy directive:
- facing issue while npm run setup HOT 2
- Opentest issue
- npm run on production environment
- Add Flow please
- npm ERR! [email protected]
- jest: not found
- Build 16x fails not 18x or 20x
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-slingshot.