Skip to content

Commit

Permalink
fix(@angular/cli): prefix historyApiFallback.index with deployUrl (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
smoke authored and sumitarora committed May 15, 2017
1 parent 0f388ea commit a5cfdde
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/@angular/cli/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ export default Task.extend({
// set publicPath property to be sent on webpack server config
if (serveTaskOptions.deployUrl) {
webpackDevServerConfiguration.publicPath = serveTaskOptions.deployUrl;
(webpackDevServerConfiguration.historyApiFallback as any).index =
serveTaskOptions.deployUrl + `/${appConfig.index}`;
}

if (serveTaskOptions.target === 'production') {
Expand Down
12 changes: 8 additions & 4 deletions tests/e2e/tests/misc/deploy-url.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { killAllProcesses } from '../../utils/process';
import { request } from '../../utils/http';
import { expectToFail } from '../../utils/utils';
import { ngServe } from '../../utils/project';

export default function () {
return Promise.resolve()
// check when setup through command line arguments
.then(() => ngServe('--deploy-url', '/deployurl', '--base-href', '/deployurl'))
.then(() => expectToFail(() => request('http://localhost:4200')))
.then(() => request('http://localhost:4200/deployurl'))
.then(() => ngServe('--deploy-url', '/deployurl/', '--base-href', '/deployurl/'))
.then(() => request('http://localhost:4200'))
.then(body => {
if (!body.match(/<app-root><\/app-root>/)) {
throw new Error('Response does not match expected value.');
}
})
.then(() => request('http://localhost:4200/deployurl/'))
.then(body => {
if (!body.match(/<app-root><\/app-root>/)) {
throw new Error('Response does not match expected value.');
Expand Down

0 comments on commit a5cfdde

Please sign in to comment.