@@ -16,10 +16,10 @@ interface ManifestCache {
16
16
[ requestSha : string ] : string ;
17
17
}
18
18
19
- const downloadManifest = async ( branchOrRef : string ) => {
19
+ const getManifest = async ( siteId : string , branchOrRef : string ) => {
20
20
const keys = [
21
- datastore . key ( [ 'Fileset2Manifest' , branchOrRef ] ) ,
22
- datastore . key ( [ 'Fileset2Manifest' , `branch :${ branchOrRef } ` ] ) ,
21
+ datastore . key ( [ 'Fileset2Manifest' , ` ${ siteId } :branch: ${ branchOrRef } ` ] ) ,
22
+ datastore . key ( [ 'Fileset2Manifest' , `${ siteId } :ref :${ branchOrRef } ` ] ) ,
23
23
] ;
24
24
const resp = await datastore . get ( keys ) ;
25
25
if ( ! resp || ! resp [ 0 ] ) {
@@ -30,28 +30,23 @@ const downloadManifest = async (branchOrRef: string) => {
30
30
if ( ! result ) {
31
31
return ;
32
32
}
33
- if ( ! result . ttls ) {
34
- return result ;
35
- }
36
33
37
- if ( result . ttls ) {
38
- // TODO: Allow this to be overwritten.
39
- const now = new Date ( ) ;
40
- let latestManifest = null ;
41
- for ( const ttlString in result . ttls ) {
42
- const ttlDate = new Date ( ttlString ) ;
43
- const isLaterThanManifestDate = now >= ttlDate ;
44
- const isLaterThanAllManifests =
45
- ! latestManifest || ttlDate >= latestManifest . ttl ;
46
- if ( isLaterThanManifestDate && isLaterThanAllManifests ) {
47
- latestManifest = result . ttls [ ttlString ] ;
48
- latestManifest . ttl = ttlDate ;
49
- }
50
- }
51
- if ( latestManifest ) {
52
- return latestManifest ;
34
+ // TODO: Allow this to be overwritten.
35
+ const now = new Date ( ) ;
36
+ let latestManifest = null ;
37
+ for ( const ttlString in result . schedule ) {
38
+ const ttlDate = new Date ( ttlString ) ;
39
+ const isLaterThanManifestDate = now >= ttlDate ;
40
+ const isLaterThanAllManifests =
41
+ ! latestManifest || ttlDate >= latestManifest . ttl ;
42
+ if ( isLaterThanManifestDate && isLaterThanAllManifests ) {
43
+ latestManifest = result . schedule [ ttlString ] ;
44
+ latestManifest . ttl = ttlDate ;
53
45
}
54
46
}
47
+ if ( latestManifest ) {
48
+ return latestManifest ;
49
+ }
55
50
return result ;
56
51
} ;
57
52
@@ -73,7 +68,7 @@ const parseHostname = (hostname: string) => {
73
68
} ;
74
69
75
70
export function createApp ( siteId : string , branchOrRef : string ) {
76
- // const startupManifest = await downloadManifest (branchOrRef);
71
+ // const startupManifest = await getManifest (branchOrRef);
77
72
console . log ( `Starting server for site: ${ siteId } @ ${ branchOrRef } ` ) ;
78
73
79
74
const app = express ( ) ;
@@ -88,7 +83,7 @@ export function createApp(siteId: string, branchOrRef: string) {
88
83
blobPath += 'index.html' ;
89
84
}
90
85
91
- const manifest = await downloadManifest ( requestBranchOrRef ) ;
86
+ const manifest = await getManifest ( requestSiteId , requestBranchOrRef ) ;
92
87
if ( ! manifest ) {
93
88
res
94
89
. status ( 404 )
@@ -99,7 +94,6 @@ export function createApp(siteId: string, branchOrRef: string) {
99
94
}
100
95
101
96
const manifestPaths = manifest . paths ;
102
-
103
97
if ( ! manifestPaths ) {
104
98
res
105
99
. status ( 404 )
@@ -129,7 +123,7 @@ export function createApp(siteId: string, branchOrRef: string) {
129
123
preserveHeaderKeyCase : true ,
130
124
} ) ;
131
125
server . on ( 'error' , ( error , req , res ) => {
132
- console . log ( `An error occurred while serving ${ req . url } ` , error ) ;
126
+ console . log ( `An error occurred while serving ${ req . url } ( ${ error } )` ) ;
133
127
} ) ;
134
128
server . on ( 'proxyRes' , ( proxyRes , req , res ) => {
135
129
delete proxyRes . headers [ 'x-cloud-trace-context' ] ;
0 commit comments