mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
Send status code to server response for redirects (#408)
Also simplified the logic a bit to reduce duplication Closes #404
This commit is contained in:
parent
036b84df90
commit
c81609d393
1 changed files with 16 additions and 19 deletions
|
@ -514,28 +514,25 @@ function execute(port) {
|
|||
app.use(siteConfig.baseUrl, express.static(CWD + '/static'));
|
||||
app.use(siteConfig.baseUrl, express.static(__dirname + '/../static'));
|
||||
|
||||
// "redirect" requests to pages ending with "/" or no extension so that
|
||||
// request to "...blog" returns same result as "...blog/index.html"
|
||||
// "redirect" requests to pages ending with "/" or no extension so that,
|
||||
// for example, request to "blog" returns same result as "blog/index.html"
|
||||
app.get(/\/[^\.]*\/?$/, (req, res) => {
|
||||
if (req.path.toString().endsWith('/')) {
|
||||
request.get(
|
||||
'http://localhost:' + port + req.path + 'index.html',
|
||||
(err, response, body) => {
|
||||
if (!err) {
|
||||
res.send(body);
|
||||
let slash = req.path.toString().endsWith('/') ? '' : '/';
|
||||
request.get(
|
||||
'http://localhost:' + port + req.path + slash + 'index.html',
|
||||
(err, response, body) => {
|
||||
console.log(response.statusCode);
|
||||
if (!err) {
|
||||
if (response) {
|
||||
res.status(response.statusCode).send(body);
|
||||
} else {
|
||||
console.error('No response');
|
||||
}
|
||||
} else {
|
||||
console.error('request failed:', err);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
request.get(
|
||||
'http://localhost:' + port + req.path + '/index.html',
|
||||
(err, response, body) => {
|
||||
if (!err) {
|
||||
res.send(body);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
app.listen(port);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue