Redirect the root only when configured (#1270)

- Fix `’INFOSITE' is not recognized` in `npm start` on Windows

Close #1259
This commit is contained in:
Paul Melnikow
2017-11-17 13:42:38 -06:00
committed by GitHub
parent 1a36054b46
commit d91b904b82
6 changed files with 21 additions and 12 deletions

View File

@@ -11,10 +11,6 @@
"repository": "https://github.com/badges/shields",
"logo": "http://shields.io/favicon.png",
"env": {
"INFOSITE": {
"description": "The home page.",
"value": "/"
},
"NPM_CONFIG_PRODUCTION": {
"description": "Configure whether devDependencies are installed (they are needed for the build).",
"value": "false"

View File

@@ -130,3 +130,17 @@ rotation logic.
[github rate limit]: https://developer.github.com/v3/#rate-limiting
[personal access tokens]: https://github.com/settings/tokens
Separate frontend hosting
-------------------------
If you want to host the frontend on a separate server, such as cloud storage
or a CDN, you can do that. Just copy the built `index.html` there.
To help out users, you can make the Shields server redirect the server root.
Set the `FRONTEND_REDIRECT_URL` environment variable:
```sh
FRONTEND_REDIRECT_URL=http://my-custom-shields.s3.amazonaws.com/
```

View File

@@ -15,7 +15,6 @@ const config = {
secureServerCert: process.env.HTTPS_CRT,
serverPort,
bindAddress,
infoSite: process.env.INFOSITE || 'https://shields.io',
githubApiUrl: process.env.GITHUB_URL || 'https://api.github.com',
frontendUri: url.format({
protocol: secureServer ? 'https' : 'http',
@@ -23,6 +22,7 @@ const config = {
port: serverPort,
pathname: '/',
}),
frontendRedirectUrl: process.env.FRONTEND_REDIRECT_URL || process.env.INFOSITE,
};
module.exports = config;

View File

@@ -60,7 +60,7 @@
"build": "npm run build:examples && npm run build:copy-fragments && npm run build:concat",
"build:production": "PRODUCTION_BUILD=true npm run build:examples && npm run build:copy-fragments && make footer-production-transform && npm run build:concat",
"heroku-postbuild": "npm run build",
"start": "INFOSITE=/ node server 8080 ::"
"start": "node server 8080 ::"
},
"bin": {
"badge": "lib/badge-cli.js"

View File

@@ -7503,11 +7503,10 @@ function(data, match, end, ask) {
}
});
if (config.infoSite !== '/') {
// Redirect the root to the website.
camp.route(/^\/$/, function(data, match, end, ask) {
if (config.frontendRedirectUrl) {
camp.route(/^\/$/, (data, match, end, ask) => {
ask.res.statusCode = 302;
ask.res.setHeader('Location', config.infoSite);
ask.res.setHeader('Location', config.frontendRedirectUrl);
ask.res.end();
});
}

View File

@@ -1,7 +1,7 @@
# Base URL for redirects etc.
BASE_URL=http://localhost:8080
# Where your homepage is
INFOSITE=http://localhost:8080/
# Where your homepage is, if different
# FRONTEND_REDIRECT_URL=http://other-server:8080/
# GitHub settings
GITHUB_URL=https://api.github.com