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.

How can i redirect this req to my declare path?

See original GitHub issue

Hello , I have some problem from useing this middleware. there is my folder:

|-statics
   |-js
      |-vender.js
|-server
   |-router
   |-views
       |-index.html
|-server.js

there is my server.js:

const express = require('express');
const path = require('path');
const history = require('connect-history-api-fallback');
const proxy = require('express-http-proxy');

const env = process.env.NODE_ENV;
const isDeveloping = (process.env.NODE_ENV != 'production');

const port = isDeveloping ? 8000 : process.env.PORT;

const app = express();
app.use('/statics', express.static('statics'));
app.use(express.static('statics'));
app.all('/api/*', proxy('http://api.ilovelook.cn'));


// i think this middleware redirect req to get '/statics/' path .
// beasuse when i move 'index.html' into 'statics' , it work right
// so my answer is how to fix this problem?
app.use(history({
    index: './server/views/index.html',
    verbose: true
}));

app.listen(port, function onStart(err) {

    if (err) {
        console.log(err);
    }
    console.info(`Listening on port ${port}. Open up http://localhost:${port}/ in your browser.`);
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bripkenscommented, Feb 10, 2017

Not quite, this middleware changes the request URL. What happens with that request is up to your application:

https://github.com/bripkens/connect-history-api-fallback/blob/master/lib/index.js#L72

0reactions
MrKou47commented, Feb 10, 2017

and this middleware just redirect view’s route to request a statics file. isn’t right?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirections in HTTP - MDN Web Docs - Mozilla
HTTP redirects are the best way to create redirections, but sometimes you don't have control over the server. In that case, try a...
Read more >
How can I redirect and rewrite my URLs with an .htaccess ...
The first path to the old file must be a local UNIX path, NOT the full path. So, if the .htaccess file is...
Read more >
Redirecting to a relative URL in JavaScript
You can do a relative redirect: window.location.href = '../'; //one level up. or window.location.href = '/path'; //relative to domain.
Read more >
Path Redirects
To view and create path redirects in SpinupWP navigate to the Path Redirects tab for a site. ... There are three parts required...
Read more >
How to use http-request redirect or http-request set-path in ...
In your backend, use http-request set-path %[path,regsub(/page-designer(.*),\1)]. This should do a regexp substitution to remove ...
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