Skip to content

Commit a5cfdde

Browse files
smokesumitarora
authored andcommitted
fix(@angular/cli): prefix historyApiFallback.index with deployUrl (#6279)
when implementing i18n following https://angular.io/docs/ts/latest/cookbook/i18n.html and https://medium.com/@feloy/deploying-an-i18n-angular-app-with-angular-cli-fc788f17e358 when running in `development` to be consistent with `production` I am using ``` ng serve --deploy-url /en/ --base-href /en/ \ --aot --locale en --i18n-file ./src/locale/messages.en.xlf ``` running the app this way, on routes other than `http://localhost:4200/en/` the `webpack-dev-server` was always saying that the route is not found, so this commit fixes that
1 parent 0f388ea commit a5cfdde

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/@angular/cli/tasks/serve.ts

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ export default Task.extend({
177177
// set publicPath property to be sent on webpack server config
178178
if (serveTaskOptions.deployUrl) {
179179
webpackDevServerConfiguration.publicPath = serveTaskOptions.deployUrl;
180+
(webpackDevServerConfiguration.historyApiFallback as any).index =
181+
serveTaskOptions.deployUrl + `/${appConfig.index}`;
180182
}
181183

182184
if (serveTaskOptions.target === 'production') {

tests/e2e/tests/misc/deploy-url.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { killAllProcesses } from '../../utils/process';
22
import { request } from '../../utils/http';
3-
import { expectToFail } from '../../utils/utils';
43
import { ngServe } from '../../utils/project';
54

65
export default function () {
76
return Promise.resolve()
87
// check when setup through command line arguments
9-
.then(() => ngServe('--deploy-url', '/deployurl', '--base-href', '/deployurl'))
10-
.then(() => expectToFail(() => request('http://localhost:4200')))
11-
.then(() => request('http://localhost:4200/deployurl'))
8+
.then(() => ngServe('--deploy-url', '/deployurl/', '--base-href', '/deployurl/'))
9+
.then(() => request('http://localhost:4200'))
10+
.then(body => {
11+
if (!body.match(/<app-root><\/app-root>/)) {
12+
throw new Error('Response does not match expected value.');
13+
}
14+
})
15+
.then(() => request('http://localhost:4200/deployurl/'))
1216
.then(body => {
1317
if (!body.match(/<app-root><\/app-root>/)) {
1418
throw new Error('Response does not match expected value.');

0 commit comments

Comments
 (0)