question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Log showed it was redirected successfully, but actually it wasn't?

See original GitHub issue

screen shot 2016-03-17 at 16 56 55 1

I’m using historyApiFallback with my express server which serves a React-App in the ‘static’ folder. And the express server only provides APIs for the React App.

I just enabled history api fallback

...
app.use(express.static(path.join(__dirname,'static')))
app.use(historyApiFallback({ verbose: true}))
app.use(bodyParser.urlencoded({ extended: true }))
app.use(apiRoutes)
...

something like this.

It’s normal if i request “http://localhost:port”, the React-App is loaded, but it i request something else, the result is shown as the picture above.

how could it happen?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
bripkenscommented, Mar 21, 2016

You need to place the historyApiFallback before the express.static handler. Also, the history API fallback only redirects internally, i.e. this is not visible to the user. Does this help?

0reactions
chimuraicommented, Jun 6, 2016

Hi @maximedupre, @bripkens

“http-proxy-middleware” also mutates the same request.url property. But in a slightly different way:

req.url = req.originalUrl; (http-proxy-middleware source)

This explains the difference in behavior… (basically ignores/overwrites the rewritten url)

Reason for this, is so you can mount is differently in express:

// example A (not applicable for Browser-Sync)
app.use('/api', proxy({target: 'http://localhost:5000'}));

// example B
app.use(proxy('/api', {target: 'http://localhost:5000'}));

Feel free to create a ticket if you think this behavior is implemented incorrectly. https://github.com/chimurai/http-proxy-middleware/issues

Read more comments on GitHub >

github_iconTop Results From Across the Web

Login successful but not redirect to another page in reactjs ...
It worked before, but now it doesn't. I thought the error was because I used loadToken () (the route as shown below) but...
Read more >
folder redirect syncs only some folders - TechNet - Microsoft
The Event Log shows "folder redirection policy application has been ... "sync completed" but none of his files from the server show up....
Read more >
How to follow redirections on a cross origin request with no ...
We'll see that the redirection does occur and the response is in fact from cors . Redirection successful. If we check our server...
Read more >
Login Does Not Redirect to Destination URL after Login
Upon successful login, the server does not redirect the page to the destination but instead redirects back to the the user's customised ...
Read more >
Tools to Determine What Apache Directive Is Forcing Redirects
Add a rewrite:trace directive to LogLevel. For more details see Apache 2.4 Documentation. Also note: Using a high trace log level for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found