Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(serve): fallback to config.app[0].index #3813

Merged
merged 3 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/angular-cli/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default Task.extend({
const ui = this.ui;

let webpackCompiler: any;
const projectConfig = CliConfig.fromProject().config;
const appConfig = projectConfig.apps[0];

let config = new NgCliWebpackConfig(
this.project,
Expand Down Expand Up @@ -84,12 +86,10 @@ export default Task.extend({
}

const webpackDevServerConfiguration: IWebpackDevServerConfigurationOptions = {
contentBase: path.resolve(
this.project.root,
`./${CliConfig.fromProject().config.apps[0].root}`
),
contentBase: path.join(this.project.root, `./${appConfig.root}`),
headers: { 'Access-Control-Allow-Origin': '*' },
historyApiFallback: {
index: `/${appConfig.index}`,
disableDotRule: true,
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
},
Expand All @@ -98,8 +98,7 @@ export default Task.extend({
proxy: proxyConfig,
compress: serveTaskOptions.target === 'production',
watchOptions: {
poll: CliConfig.fromProject().config.defaults &&
CliConfig.fromProject().config.defaults.poll
poll: projectConfig.defaults && projectConfig.defaults.poll
},
https: serveTaskOptions.ssl
};
Expand Down
33 changes: 33 additions & 0 deletions tests/e2e/tests/misc/fallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { request } from '../../utils/http';
import { killAllProcesses } from '../../utils/process';
import { ngServe } from '../../utils/project';
import { updateJsonFile } from '../../utils/project';
import { moveFile } from '../../utils/fs';


export default function () {
// should fallback to config.app[0].index (index.html by default)
return Promise.resolve()
.then(() => ngServe())
.then(() => request('http://localhost:4200/'))
.then(body => {
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
throw new Error('Response does not match expected value.');
}
})
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; })
// should correctly fallback to a changed index
.then(() => moveFile('src/index.html', 'src/not-index.html'))
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['index'] = 'not-index.html';
}))
.then(() => ngServe())
.then(() => request('http://localhost:4200/'))
.then(body => {
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
throw new Error('Response does not match expected value.');
}
})
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
}
6 changes: 5 additions & 1 deletion tests/e2e/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import * as _request from 'request';

export function request(url: string): Promise<string> {
return new Promise((resolve, reject) => {
let options = { url: url, agentOptions: { rejectUnauthorized: false }};
let options = {
url: url,
headers: { 'Accept': 'text/html' },
agentOptions: { rejectUnauthorized: false }
};
_request(options, (error: any, response: IncomingMessage, body: string) => {
if (error) {
reject(error);
Expand Down