Skip to content

Commit 931e2b3

Browse files
committed
DON-66 - fix index replacements + favicons
See angular/angular-cli#10881 for discussion on replacing index files per-environment
1 parent 1075b08 commit 931e2b3

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

angular.json

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
{
4040
"replace": "src/environments/environment.ts",
4141
"with": "src/environments/environment.production.ts"
42-
},
43-
{
44-
"replace": "src/index.html",
45-
"with": "src/index.production.html"
4642
}
4743
],
44+
"index": {
45+
"input": "src/index.production.html",
46+
"output": "index.html"
47+
},
4848
"optimization": true,
4949
"outputHashing": "all",
5050
"sourceMap": false,
@@ -67,12 +67,12 @@
6767
{
6868
"replace": "src/environments/environment.ts",
6969
"with": "src/environments/environment.staging.ts"
70-
},
71-
{
72-
"replace": "src/index.html",
73-
"with": "src/index.staging.html"
7470
}
7571
],
72+
"index": {
73+
"input": "src/index.staging.html",
74+
"output": "index.html"
75+
},
7676
"optimization": true,
7777
"outputHashing": "all",
7878
"sourceMap": false,
@@ -165,10 +165,6 @@
165165
{
166166
"replace": "src/environments/environment.ts",
167167
"with": "src/environments/environment.production.ts"
168-
},
169-
{
170-
"replace": "src/index.html",
171-
"with": "src/index.production.html"
172168
}
173169
]
174170
},
@@ -177,10 +173,6 @@
177173
{
178174
"replace": "src/environments/environment.ts",
179175
"with": "src/environments/environment.staging.ts"
180-
},
181-
{
182-
"replace": "src/index.html",
183-
"with": "src/index.staging.html"
184176
}
185177
]
186178
}

server.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,26 @@ app.get('/robots.txt', (req, res) => {
4949
});
5050

5151
// Serve static files requested via /d/ from /browser/d - when deployed S3 serves these up to CloudFront
52+
app.get('/d/favicon.ico', (req, res) => {
53+
res.sendFile(DIST_FOLDER + '/favicon.ico', {
54+
maxAge: '7 days', // Don't make the favicon immutable in case we want to update it
55+
});
56+
});
57+
5258
app.use('/d', express.static(DIST_FOLDER, {
53-
immutable: true,
54-
maxAge: '1y',
59+
immutable: true, // Everything in here should be named with an immutable hash
60+
maxAge: '1 year',
5561
}));
5662

57-
// And similar for /assets
5863
app.use('/assets', express.static(DIST_FOLDER + '/assets', {
59-
maxAge: '1d',
64+
maxAge: '1 day', // Assets should be served similarly but don't have name-hashes
6065
}));
6166

6267
// All regular routes use the Universal engine
6368
app.get('*', (req, res) => {
69+
// Note that the file output as `index.html` is actually dynamic. See `index` config keys in `angular.json`.
70+
// See https://github.com/angular/angular-cli/issues/10881#issuecomment-530864193 for info on the undocumented use of
71+
// this key to work around `fileReplacements` ending index support in Angular 8.
6472
res.render('index', { req });
6573
});
6674

0 commit comments

Comments
 (0)