Skip to content

Commit

Permalink
support subdomain + suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
chandde committed Jul 30, 2020
1 parent cd7af3d commit 074a16a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions uiserver/config/default.json
Expand Up @@ -2,8 +2,8 @@
"Cdn": "https://bingadssmartpagetest2.azureedge.net/",
"Blob": "https://bingadssmartpagetest2.z19.web.core.windows.net/",
"Host": "bingadssmartpagetest2.centralus.cloudapp.azure.com",
"FullCustomDomain": "www.bingadssmartpagetest3.com",
"CustomDomain": "bingadssmartpagetest3.com",
"WWWDomain": "www.bingadssmartpagetest3.com",
"NakedDomain": "bingadssmartpagetest3.com",
"TrafficManager": "bingadssmartpagetest2.trafficmanager.net",
"HttpPort": 80,
"HttpsPort": 443,
Expand Down
44 changes: 24 additions & 20 deletions uiserver/server.js
Expand Up @@ -37,8 +37,8 @@ log(`https listening on port ${HttpsPort}`);
const Cdn = config.get('Cdn');
const Host = config.get('Host');
const Blob = config.get('Blob');
const FullCustomDomain = config.get('FullCustomDomain');
const CustomDomain = config.get('CustomDomain');
const WWWDomain = config.get('WWWDomain');
const NakedDomain = config.get('NakedDomain');
const TrafficManager = config.get('TrafficManager');

const customDomainMap = {};
Expand Down Expand Up @@ -116,22 +116,26 @@ async function populateHtml(site) {
// only support l1 request if user is accessing by host or by custom domain
// e.g. www.smartpage.com/site1
// or smartpage.centralus.cloudapp.azure.net/site1
// app.use('/:l1', function (req, res) {
// log(`handling request ${req.headers.host}${req.originalUrl}`);
// if (req.headers.host === FullCustomDomain
// || req.headers.host === Host
// || req.headers.host === TrafficManager
// ) {
// // user is accessing www.smartpage.com/site1
// populateHtml(req.originalUrl.substring(1)).then((indexHtml) => {
// res.send(indexHtml);
// });
// }
// else {
// res.status(404).send("Page not found!");
// }
// // }
// });
// or contoso.smartpage.com/suffix
app.use('/:l1', function (req, res) {
log(`handling request ${req.headers.host}${req.originalUrl}`);
if (req.headers.host === WWWDomain
|| req.headers.host === Host
|| req.headers.host === TrafficManager
|| req.headers.host.indexOf(NakedDomain) > 0
) {
// user is accessing x.smartpage.com/y
const subdomain = req.headers.host.substring(0, req.headers.host.indexOf(NakedDomain) - 1);
const suffix = req.originalUrl.substring(1);
populateHtml(subdomain + '/' + suffix).then((indexHtml) => {
res.send(indexHtml);
});
}
else {
res.status(404).send("Page not found!");
}
// }
});

// only allow root access from subdomain, or domain from customer
// e.g. cars.smartpage.com, in this case we need to find the mapping
Expand All @@ -140,8 +144,8 @@ async function populateHtml(site) {
app.use('/', function (req, res) {
log(`handling request ${req.headers.host}${req.originalUrl}`);
// log(req);
if (req.headers.host !== FullCustomDomain && req.headers.host.indexOf(CustomDomain) > 0) {
const subdomain = req.headers.host.substring(0, req.headers.host.indexOf(CustomDomain) - 1);
if (req.headers.host !== WWWDomain && req.headers.host.indexOf(NakedDomain) > 0) {
const subdomain = req.headers.host.substring(0, req.headers.host.indexOf(NakedDomain) - 1);
// getSubdomainMapping(subdomain).then((site) => {
populateHtml(subdomain).then((indexHtml) => {
res.send(indexHtml);
Expand Down

0 comments on commit 074a16a

Please sign in to comment.