Skip to content

Commit

Permalink
Merge pull request #155 from Automattic/fix/duplicate-containers-redi…
Browse files Browse the repository at this point in the history
…rect

Gets environment during proxy to redirect to right container
  • Loading branch information
ChaosExAnima authored Apr 28, 2020
2 parents e823cf3 + 3dd1d73 commit edad41d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ export function isContainerRunning( hash: CommitHash, env?: RunEnv ): boolean {
return !! getRunningContainerForHash( hash, env );
}

export function getPortForContainer( hash: CommitHash ): number | boolean {
const container = getRunningContainerForHash( hash );
export function getPortForContainer( hash: CommitHash, env: RunEnv ): number | boolean {
const container = getRunningContainerForHash( hash, env );

if ( ! container ) {
return false;
Expand Down Expand Up @@ -458,11 +458,11 @@ export async function cleanupExpiredContainers() {

const proxy = httpProxy.createProxyServer( {} ); // See (†)
export async function proxyRequestToHash( req: any, res: any ) {
const commitHash = req.session.commitHash;
let port = await getPortForContainer( commitHash );
const { commitHash, runEnv } = req.session;
let port = await getPortForContainer( commitHash, runEnv );

if ( ! port ) {
l.log( { port, commitHash }, `Could not find port for commitHash` );
l.log( { port, commitHash, runEnv }, `Could not find port for commitHash` );
res.send( 'Error setting up port!' );
res.end();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function assembleSubdomainUrlForHash( req: express.Request, commitHash: CommitHa
const newUrl = new URL( `${protocol}://${subdomainEnv}hash-${commitHash}.${stripCommitHashSubdomainFromHost( req.headers.host )}` );
newUrl.pathname = req.path;
for ( let [ key, value ] of Object.entries( req.query ) ) {
if ( key === 'hash' || key === 'branch' ) {
if ( key === 'hash' || key === 'branch' || key === 'env' ) {
continue;
}
newUrl.searchParams.set( key, String( value ) );
Expand Down

0 comments on commit edad41d

Please sign in to comment.