Skip to content

Commit

Permalink
fix(@nguniversal/builders): add support to serve service workers
Browse files Browse the repository at this point in the history
Previously, for legacy reasons service workers were not served when using the `ssr-dev-server` builders. This commit enabled serving of service workers as now service workers can be served without valid SSL when served using localhost.

(cherry picked from commit 52aa9ef)
  • Loading branch information
alan-agius4 committed Apr 12, 2023
1 parent 369c88f commit 15a46b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 29 additions & 0 deletions modules/builders/src/ssr-dev-server/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,35 @@ describe('Serve SSR Builder', () => {
expect(await response.text()).toContain('<title>App</title>');
});

it('works with service-worker', async () => {
const manifest = {
index: '/index.html',
assetGroups: [
{
name: 'app',
installMode: 'prefetch',
resources: {
files: ['/index.html'],
},
},
],
};

host.writeMultipleFiles({
'ngsw-config.json': JSON.stringify(manifest),
});

const run = await architect.scheduleTarget(target, {
port: 7003,
browserTarget: 'app:build:sw',
});
runs.push(run);
const output = await run.result;
expect(output.success).toBe(true);
const response = await fetch('http://localhost:7003/ngsw.json');
expect(await response?.text()).toContain('installMode');
});

// todo: alan-agius4: Investigate why this tests passed locally but fails in CI.
// this is currenty disabled but still useful locally
xit('works with rebuilds with fetch', async () => {
Expand Down
1 change: 0 additions & 1 deletion modules/builders/src/ssr-dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export function execute(
const getBaseUrl = (bs: browserSync.BrowserSyncInstance) =>
`${bs.getOption('scheme')}://${bs.getOption('host')}:${bs.getOption('port')}`;
const browserTargetRun = context.scheduleTarget(browserTarget, {
serviceWorker: false,
watch: true,
progress: options.progress,
verbose: options.verbose,
Expand Down

0 comments on commit 15a46b8

Please sign in to comment.