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

Use request body to send the host instead of query parameter #4

Open
wants to merge 2 commits into
base: master
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
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const proxy = require('http-proxy-middleware');

var app = express();

app.use(express.static('public'))
app.use(express.urlencoded({ extended: true }));
app.use(express.static('public'));
app.engine('html', require('ejs').renderFile);
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
Expand All @@ -19,7 +20,7 @@ app.get('/', (req, res) => {
});

var onProxyReq = function (proxyReq, req, res) {
const host = req.query.host || req.headers.host;
const host = req.query.host || (req.body && req.body.host) || req.headers.host;
console.log(req.query.host);
console.log('host', host);
proxyReq.setHeader('x-login-host', host);
Expand Down
11 changes: 4 additions & 7 deletions views/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,11 @@
document.getElementById('info').classList.toggle('active');
}

function getNext() {
var next = /next=(.*)/.exec(window.location.search); // assuming only search param
return next ? '&next=' + next[1] : '';
}

window.onload = function() {
var form = document.getElementById('loginForm');
var inputHost = document.getElementById('inputHost');
form.addEventListener('submit', onSubmit);
form.setAttribute('action', '/login?host='+ window.location.host + getNext());
inputHost.value = window.location.host;
}
</script>
</head>
Expand Down Expand Up @@ -329,7 +325,8 @@ <h1>Redash Preview Instance</h1>
</div>
</div>

<form method="post" action="/login" name="login" id="loginForm" onsubmit="onSubmit">
<form method="post" name="login" id="loginForm" onsubmit="onSubmit">
<input name="host" type="hidden" id="inputHost">
<input name="email" type="email" id="inputEmail" placeholder="Email address" required autofocus>
<input name="password" type="password" id="inputPassword" placeholder="Password" required>
<button type="submit" id="submitButton">
Expand Down