Skip to content

Commit 9fc42b1

Browse files
committed
fix(@angular-devkit/build-angular): resolve dev-server sslKey and sslCert relative to the workspace root
Previously, the esbuild-based dev-server passed relative `sslKey` and `sslCert` paths to Vite as is, so they were read relative to the current directory and `ng serve` failed with ENOENT when run outside the workspace root. The paths are now resolved against the workspace root, matching `@angular/build`.
1 parent 83c6edd commit 9fc42b1

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

‎packages/angular_devkit/build_angular/src/builders/dev-server/options.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ export async function normalizeOptions(
144144
servePath,
145145
publicHost,
146146
ssl,
147-
sslCert,
148-
sslKey,
147+
sslCert: sslCert && path.resolve(workspaceRoot, sslCert),
148+
sslKey: sslKey && path.resolve(workspaceRoot, sslKey),
149149
forceEsbuild,
150150
// Prebundling defaults to true but requires caching to function
151151
prebundle: cacheOptions.enabled && !optimization.scripts && (prebundle ?? true),
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { executeDevServer } from '../../index';
10+
import { describeServeBuilder } from '../jasmine-helpers';
11+
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';
12+
13+
const SSL_KEY = `-----BEGIN PRIVATE KEY-----
14+
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgEpythQjrJo9bm8GM
15+
LFacGutCqc/XxDZ3dDkSMYZYZ2ehRANCAARvwtZ3OwP1uLhrcLp7nemvaWqkA+FN
16+
NDjOA3OZKhyVHYog1jNTawJJjwk66upbXGFL8622yU1INWbZFxvrSANl
17+
-----END PRIVATE KEY-----
18+
`;
19+
20+
const SSL_CERT = `-----BEGIN CERTIFICATE-----
21+
MIIBfzCCASWgAwIBAgIUUoRhwzxAE3y5nrOW8de+cJEIVvQwCgYIKoZIzj0EAwIw
22+
FDESMBAGA1UEAwwJbG9jYWxob3N0MCAXDTI2MTAxOTA4NTUyNVoYDzIxMjYwOTI1
23+
MDg1NTI1WjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwWTATBgcqhkjOPQIBBggqhkjO
24+
PQMBBwNCAARvwtZ3OwP1uLhrcLp7nemvaWqkA+FNNDjOA3OZKhyVHYog1jNTawJJ
25+
jwk66upbXGFL8622yU1INWbZFxvrSANlo1MwUTAdBgNVHQ4EFgQUWyqB1QeFcs6L
26+
LL7Utsybm6+XFvIwHwYDVR0jBBgwFoAUWyqB1QeFcs6LLL7Utsybm6+XFvIwDwYD
27+
VR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNIADBFAiBazry25W+Qewb/WzadhmdY
28+
YDGdshNZCk0g0DI3ctNjlgIhAKm2X8pmqdkM38Yh8QDN0cHBsAcDfRYffDnjJ3tP
29+
dpnU
30+
-----END CERTIFICATE-----
31+
`;
32+
33+
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
34+
describe('option: "ssl"', () => {
35+
beforeEach(async () => {
36+
setupTarget(harness);
37+
38+
// Application code is not needed for these tests
39+
await harness.writeFile('src/main.ts', '');
40+
});
41+
42+
it('resolves "sslKey" and "sslCert" relative to the workspace root', async () => {
43+
await harness.writeFile('ssl/server.key', SSL_KEY);
44+
await harness.writeFile('ssl/server.crt', SSL_CERT);
45+
46+
harness.useTarget('serve', {
47+
...BASE_OPTIONS,
48+
ssl: true,
49+
sslKey: 'ssl/server.key',
50+
sslCert: 'ssl/server.crt',
51+
});
52+
53+
const { result } = await harness.executeOnce();
54+
55+
expect(result?.success).toBeTrue();
56+
expect(result?.baseUrl).toMatch(/^https:\/\/[^/]+:\d+\//);
57+
});
58+
});
59+
});

0 commit comments

Comments
 (0)