How can i redirect this req to my declare path?
See original GitHub issueHello , 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:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
and this middleware just redirect view’s route to request a statics file. isn’t right?