-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular):
baseHref
with trailing slash ca…
…uses server not to be accessible without trailing slash This commit fixes an issue were when using a `baseHref` with trailing slash, vite dev-server would have been only accessible via a URL with a trailing slash. As vite would redirect to an error page similar to the below; ``` The server is configured with a public base URL of /myapp/ - did you mean to visit [/myapp/](http://localhost:4200/myapp/) instead? ``` Closes: #26618 (cherry picked from commit 4b3a965)
- Loading branch information
1 parent
4b3af73
commit 3df3e58
Showing
2 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...gular_devkit/build_angular/src/builders/dev-server/tests/behavior/build-base-href_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC 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 { executeDevServer } from '../../index'; | ||
import { executeOnceAndFetch } from '../execute-fetch'; | ||
import { describeServeBuilder } from '../jasmine-helpers'; | ||
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup'; | ||
|
||
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => { | ||
describe('Behavior: "buildTarget baseHref"', () => { | ||
beforeEach(async () => { | ||
setupTarget(harness, { | ||
baseHref: '/test/', | ||
}); | ||
|
||
// Application code is not needed for these tests | ||
await harness.writeFile('src/main.ts', 'console.log("foo");'); | ||
}); | ||
|
||
it('uses the baseHref defined in the "buildTarget" options as the serve path', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
}); | ||
|
||
const { result, response } = await executeOnceAndFetch(harness, '/test/main.js'); | ||
|
||
expect(result?.success).toBeTrue(); | ||
const baseUrl = new URL(`${result?.baseUrl}/`); | ||
expect(baseUrl.pathname).toBe('/test/'); | ||
expect(await response?.text()).toContain('console.log'); | ||
}); | ||
|
||
it('serves the application from baseHref location without trailing slash', async () => { | ||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
}); | ||
|
||
const { result, response } = await executeOnceAndFetch(harness, '/test'); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(await response?.text()).toContain('<script src="main.js" type="module">'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters