diff --git a/app.json b/app.json index 7499a4b878..b14d16d58d 100644 --- a/app.json +++ b/app.json @@ -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" diff --git a/doc/self-hosting.md b/doc/self-hosting.md index 433b3590c9..b3267ae237 100644 --- a/doc/self-hosting.md +++ b/doc/self-hosting.md @@ -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/ +``` diff --git a/lib/server-config.js b/lib/server-config.js index 4f1975e50f..b298711ebf 100644 --- a/lib/server-config.js +++ b/lib/server-config.js @@ -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; diff --git a/package.json b/package.json index 4c160ad801..83ff16a35e 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/server.js b/server.js index 24c535e360..718513ff38 100644 --- a/server.js +++ b/server.js @@ -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(); }); } diff --git a/shields.example.env b/shields.example.env index 8e23d487d7..5fb6d15008 100644 --- a/shields.example.env +++ b/shields.example.env @@ -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