Skip to content

Commit a631471

Browse files
committed
fix(serve): fallback to config.app[0].index
Fix #3748
1 parent ba477d3 commit a631471

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

packages/angular-cli/tasks/serve-webpack.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default Task.extend({
1919
const ui = this.ui;
2020

2121
let webpackCompiler: any;
22+
const projectConfig = CliConfig.fromProject().config;
23+
const appConfig = projectConfig.apps[0];
2224

2325
let config = new NgCliWebpackConfig(
2426
this.project,
@@ -84,12 +86,10 @@ export default Task.extend({
8486
}
8587

8688
const webpackDevServerConfiguration: IWebpackDevServerConfigurationOptions = {
87-
contentBase: path.resolve(
88-
this.project.root,
89-
`./${CliConfig.fromProject().config.apps[0].root}`
90-
),
89+
contentBase: path.resolve(this.project.root, `./${appConfig.root}`),
9190
headers: { 'Access-Control-Allow-Origin': '*' },
9291
historyApiFallback: {
92+
index: `/${appConfig.index}`,
9393
disableDotRule: true,
9494
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
9595
},
@@ -98,7 +98,7 @@ export default Task.extend({
9898
proxy: proxyConfig,
9999
compress: serveTaskOptions.target === 'production',
100100
watchOptions: {
101-
poll: CliConfig.fromProject().config.defaults.poll
101+
poll: projectConfig.defaults.poll
102102
},
103103
https: serveTaskOptions.ssl
104104
};

tests/e2e/tests/misc/fallback.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { request } from '../../utils/http';
2+
import { killAllProcesses } from '../../utils/process';
3+
import { ngServe } from '../../utils/project';
4+
import { updateJsonFile } from '../../utils/project';
5+
import { moveFile } from '../../utils/fs';
6+
7+
8+
export default function () {
9+
// should fallback to config.app[0].index (index.html by default)
10+
return Promise.resolve()
11+
.then(() => ngServe())
12+
.then(() => request('http://localhost:4200/'))
13+
.then(body => {
14+
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
15+
throw new Error('Response does not match expected value.');
16+
}
17+
})
18+
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; })
19+
// should correctly fallback to a changed index
20+
.then(() => moveFile('src/index.html', 'src/not-index.html'))
21+
.then(() => updateJsonFile('angular-cli.json', configJson => {
22+
const app = configJson['apps'][0];
23+
app['index'] = 'not-index.html';
24+
}))
25+
.then(() => ngServe())
26+
.then(() => request('http://localhost:4200/'))
27+
.then(body => {
28+
console.log(body)
29+
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
30+
throw new Error('Response does not match expected value.');
31+
}
32+
})
33+
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
34+
}

0 commit comments

Comments
 (0)