I'm hoping to better understand the difference between express's app.get()
and app.use()
.
I understand that app.use applies to all HTTP verbs.
I have also read that "app.use()
adds middleware rather than a route"
I'd like to understand why this fact causes this behaviour...
I have an express API server that needs to proxy a React development web server.
This means that all routes that are not API routes have to be proxied.
When I proxy the routes like this, it works:
var proxy = require('express-http-proxy');
module.exports = function set_react_catchall_routes(app) {
/* Final route to send anything else to react server. */
app.get('*', proxy('localhost:3000'));
app.post('*', proxy('localhost:3000'));
}
But when I do this it does not work:
app.use('*', proxy('localhost:3000'));
Specifically, the "index" page is proxied and served up, with content like this:
<body>
<div id="root"></div>
<script type="text/javascript" src="/static/js/bundle.js"></script>
</body>
and the client requests the javascript react bundle, but then "nothing happens".
I'm reasonably sure that there aren't "other" HTTP requests involved when it does work (other than GET and POST) because none are logged.
So what would be the difference?