mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +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(CWD + '/static'));
|
||||||
app.use(siteConfig.baseUrl, express.static(__dirname + '/../static'));
|
app.use(siteConfig.baseUrl, express.static(__dirname + '/../static'));
|
||||||
|
|
||||||
// "redirect" requests to pages ending with "/" or no extension so that
|
// "redirect" requests to pages ending with "/" or no extension so that,
|
||||||
// request to "...blog" returns same result as "...blog/index.html"
|
// for example, request to "blog" returns same result as "blog/index.html"
|
||||||
app.get(/\/[^\.]*\/?$/, (req, res) => {
|
app.get(/\/[^\.]*\/?$/, (req, res) => {
|
||||||
if (req.path.toString().endsWith('/')) {
|
let slash = req.path.toString().endsWith('/') ? '' : '/';
|
||||||
request.get(
|
request.get(
|
||||||
'http://localhost:' + port + req.path + 'index.html',
|
'http://localhost:' + port + req.path + slash + 'index.html',
|
||||||
(err, response, body) => {
|
(err, response, body) => {
|
||||||
if (!err) {
|
console.log(response.statusCode);
|
||||||
res.send(body);
|
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);
|
app.listen(port);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue