@@ -51,21 +51,24 @@ const getManifest = async (siteId: string, branchOrRef: string) => {
51
51
// }
52
52
} ;
53
53
54
- export function parseHostname ( hostname : string ) {
55
- // TODO: Make this more robust
56
- if ( hostname . includes ( '-dot-' ) ) {
57
- const prefix = hostname . split ( '-dot-fileset2-' ) [ 0 ] ;
58
- const parts = prefix . split ( '-' ) ; // Either site-ref or site.
59
- return {
60
- siteId : parts [ 0 ] ,
61
- branchOrRef : parts . length > 1 ? parts [ 1 ] . slice ( 0 , 7 ) : 'master' ,
62
- } ;
63
- } else {
64
- return {
65
- siteId : '' ,
66
- branchOrRef : '' ,
67
- } ;
54
+ export function parseHostname ( hostname : string , defaultSiteId ?: string , defaultLiveDomain ?: string ) {
55
+ let siteId = defaultSiteId || 'default' ;
56
+ let branchOrRef = '' ;
57
+ if ( hostname == defaultLiveDomain ) {
58
+ // Hostname is the "live" or "prod" domain. Use the master branch.
59
+ branchOrRef = 'master' ;
60
+ } else if ( hostname . includes ( '-dot-' ) ) {
61
+ // Use "-dot-" as a sentinel for App Engine wildcard domains.
62
+ const prefix = hostname . split ( '-dot-' ) [ 0 ] ;
63
+ const parts = prefix . split ( '-' ) ; // Either <Site>-<Ref> or <Site>.
64
+ siteId = parts [ 0 ] ;
65
+ branchOrRef = parts . length > 1 ? parts [ 1 ] . slice ( 0 , 7 ) : 'master' ;
68
66
}
67
+ // TODO: Implement defaultStagingDomain (custom staging domain) support.
68
+ return {
69
+ siteId : siteId ,
70
+ branchOrRef : branchOrRef ,
71
+ } ;
69
72
}
70
73
71
74
export function createApp ( siteId : string , branchOrRef : string ) {
@@ -74,7 +77,7 @@ export function createApp(siteId: string, branchOrRef: string) {
74
77
const app = express ( ) ;
75
78
app . disable ( 'x-powered-by' ) ;
76
79
app . all ( '/*' , async ( req : express . Request , res : express . Response ) => {
77
- const envFromHostname = parseHostname ( req . hostname ) ;
80
+ const envFromHostname = parseHostname ( req . hostname , process . env . FILESET_SITE , process . env . FILESET_LIVE_DOMAIN ) ;
78
81
const requestSiteId = envFromHostname . siteId || siteId ;
79
82
const requestBranchOrRef = envFromHostname . branchOrRef || branchOrRef ;
80
83
0 commit comments