This repository has been archived by the owner on Jul 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from Wikia/XW-3247
XW-3247 | Handle externaltest and showcase subdomains
- Loading branch information
1 parent
23b7f29
commit cede844
Showing
5 changed files
with
70 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @param {Object} request - FastBoot request | ||
* @returns {string} | ||
*/ | ||
export default function getHostFromRequest(request) { | ||
// We use two special domain prefixes for Ad Operations and Sales reasons | ||
// Their purpose is to allow separate targeting by having a different domain in the browser | ||
// We still want to call production API with non-prefixed host | ||
// See https://github.com/Wikia/wikia-vcl/blob/master/wikia.com/control-stage.vcl | ||
const headers = request.get('headers'); | ||
// One of our layers cuts out sandbox-* prefix from the host, use x-original-host instead | ||
let host = headers.get('x-original-host') || request.get('host'); | ||
|
||
if (headers.get('x-staging') === 'externaltest') { | ||
host = host.replace(/^(externaltest|showcase)\./, ''); | ||
} | ||
|
||
return host; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {module} from 'qunit'; | ||
import {test} from 'ember-qunit'; | ||
|
||
module('Unit | Utility | host', () => { | ||
test('returns correct host', (assert) => { | ||
const testCases = [ | ||
{ | ||
headers: {}, | ||
host: 'starwars.wikia.com', | ||
expected: 'starwars.wikia.com', | ||
}, | ||
{ | ||
headers: { | ||
'x-original-host': 'sandbox-xw1.starwars.wikia.com' | ||
}, | ||
host: 'starwars.wikia.com', | ||
expected: 'sandbox-xw1.starwars.wikia.com', | ||
}, | ||
{ | ||
headers: { | ||
'x-original-host': 'externaltest.starwars.wikia.com', | ||
'x-staging': 'externaltest' | ||
}, | ||
host: 'starwars.wikia.com', | ||
expected: 'starwars.wikia.com', | ||
}, | ||
{ | ||
headers: { | ||
'x-original-host': 'starwars.wikia.com', | ||
'x-staging': 'externaltest' | ||
}, | ||
host: 'showcase.starwars.wikia.com', | ||
expected: 'starwars.wikia.com', | ||
}, | ||
]; | ||
|
||
testCases.forEach((testCase) => { | ||
const request = Ember.Object.create(); | ||
|
||
request.setProperties({ | ||
headers: Ember.Object.create(testCase.headers), | ||
host: testCase.host | ||
}); | ||
|
||
assert.strictEqual(require('mobile-wiki/utils/host').default(request), testCase.expected); | ||
}); | ||
}); | ||
}); |