Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable localhost reverse proxy serving #3422

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions build-system/server/server-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ app.engine('html', require('hogan-express'));
app.locals.delimiters = '<% %>';

// HTTPS redirect.
app.set('trust proxy', 'loopback');
app.use((req, res, next) => {
let host = req.headers.host || req.host;
let host = req.headers.host || req.hostname || req.host;
const secure =
req.secure ||
req.connection.encrypted ||
req.get('X-Forwarded-Proto') === 'https';
if (secure || host.indexOf('localhost') != -1) {
if (
secure ||
host.indexOf('localhost') != -1 ||
host === process.env.PROXY_URL
) {
// Skip localhost or if already secure.
next();
return;
Expand Down
4 changes: 2 additions & 2 deletions build-system/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const isRunning = require('is-running');
const log = require('fancy-log');
const webserver = require('gulp-webserver');

const host = process.env.SERVE_HOST;
const port = process.env.SERVE_PORT;
const host = process.env.SERVE_HOST || process.env.HOST;
const port = process.env.SERVE_PORT || process.env.PORT;
const useHttps = process.env.SERVE_USEHTTPS == 'true' ? true : false;
const gulpProcess = process.env.SERVE_PROCESS_ID;
const quiet = process.env.SERVE_QUIET == 'true' ? true : false;
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const args = require('./args');
const log = require('fancy-log');
const nodemon = require('nodemon');

const host = args.host || 'localhost';
const host = args.host || process.env.HOST || 'localhost';
const port = args.port || process.env.PORT || 8000;
const useHttps = args.https != undefined;
const quiet = args.quiet != undefined;
Expand Down
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (!isCiBuild()) {
}

const $$ = require('gulp-load-plugins')();
require('dotenv').config(); // eslint-disable-line
const gulp = $$.help(require('gulp'));
const {assets} = require('./build-system/tasks/assets');
const {build, clean, watch} = require('./build-system/tasks/builders');
Expand Down
109 changes: 28 additions & 81 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"chai-as-promised": "7.1.1",
"cssnano": "6.0.3",
"del": "7.1.0",
"dotenv": "^16.4.4",
"eslint": "8.56.0",
"eslint-plugin-google-camelcase": "0.0.2",
"eslint-plugin-prettier": "4.2.1",
Expand Down
Loading