Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,14 @@
"type": "string",
"description": "The URL that the browser client (or live-reload client, if enabled) should use to connect to the development server. Use for a complex dev server setup, such as one with reverse proxies."
},
"allowedHosts": {
"type": "array",
"description": "Whitelist of hosts that are allowed to access the dev server.",
"default": [],
"items": {
"type": "string"
}
},
"servePath": {
"type": "string",
"description": "The pathname where the app will be served."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export function buildServerConfig(
// inline is always false, because we add live reloading scripts in _addLiveReload when needed
inline: false,
public: serverOptions.publicHost,
allowedHosts: serverOptions.allowedHosts,
disableHostCheck: serverOptions.disableHostCheck,
publicPath: servePath,
hot: serverOptions.hmr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
"type": "string",
"description": "The URL that the browser client (or live-reload client, if enabled) should use to connect to the development server. Use for a complex dev server setup, such as one with reverse proxies."
},
"allowedHosts": {
"type": "array",
"description": "Whitelist of hosts that are allowed to access the dev server.",
"default": [],
"items": {
"type": "string"
}
},
"servePath": {
"type": "string",
"description": "The pathname where the app will be served."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Architect, BuilderRun } from '@angular-devkit/architect';
import fetch from 'node-fetch'; // tslint:disable-line:no-implicit-dependencies
import { DevServerBuilderOutput } from '../../src/dev-server';
import { createArchitect, host } from '../utils';


describe('Dev Server Builder allowed host', () => {
// We have to spoof the host to a non-numeric one because Webpack Dev Server does not
// check the hosts anymore when requests come from numeric IP addresses.
const headers = { host: 'spoofy.mcspoofface' };

const target = { project: 'app', target: 'serve' };
let architect: Architect;
// We use runs like this to ensure it WILL stop the servers at the end of each tests.
let runs: BuilderRun[];

beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
runs = [];
});
afterEach(async () => {
await host.restore().toPromise();
await Promise.all(runs.map(r => r.stop()));
});

it('works', async () => {
const run = await architect.scheduleTarget(target, { allowedHosts: ['spoofy.mcspoofface'] });
runs.push(run);
const output = await run.result as DevServerBuilderOutput;
expect(output.success).toBe(true);
expect(output.baseUrl).toBe('http://localhost:4200/');

const response = await fetch(`${output.baseUrl}`, { headers });
expect(await response.text()).toContain('<title>HelloWorldApp</title>');
}, 30000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createArchitect, host } from '../utils';
describe('Dev Server Builder public host', () => {
// We have to spoof the host to a non-numeric one because Webpack Dev Server does not
// check the hosts anymore when requests come from numeric IP addresses.
const headers = { host: 'http://spoofy.mcspoofface' };
const headers = { host: 'spoofy.mcspoofface' };

const target = { project: 'app', target: 'serve' };
let architect: Architect;
Expand Down