Skip to content

Commit

Permalink
fix(builders): don't spawn server until browser build finishes
Browse files Browse the repository at this point in the history
In some cases, we spawned the server to early, which caused the views not to be found. This happened when the browser build too a long time.

With this change we spawn the server only after both browser and server have emitted.
  • Loading branch information
alan-agius4 committed Mar 10, 2020
1 parent 5a52406 commit a279fa6
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions modules/builders/src/ssr-dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,24 @@ export function execute(
getAvailablePort(),
).pipe(
switchMap(([br, sr, nodeServerPort]) => {
const server$ = sr.output.pipe(
switchMap(s => {
if (!s.success) {
return of(s);
return combineLatest([br.output, sr.output]).pipe(
// This is needed so that if both server and browser emit close to each other
// we only emit once. This typically happens on the first build.
debounceTime(120),
switchMap(([b, s]) => {
if (!s.success || !b.success) {
return of([b, s]);
}

return startNodeServer(s, nodeServerPort, context.logger).pipe(
mapTo(s),
mapTo([b, s]),
catchError(err => {
context.logger.error(`A server error has occurred.\n${mapErrorToMessage(err)}`);

return EMPTY;
}),
);
}));

return combineLatest([br.output, server$]).pipe(
// This is needed so that if both server and browser emit close to each other
// we only emit once. This typically happens on the first build.
debounceTime(120),
}),
map(([b, s]) => ([
{
success: b.success && s.success,
Expand Down Expand Up @@ -265,18 +263,18 @@ async function initBrowserSync(
if (hasPathname) {
// Remove leading slash
bsOptions.scriptPath = p => p.substring(1),
bsOptions.middleware = [
createProxyMiddleware(defaultSocketIoPath, {
target: url.format({
protocol: 'http',
hostname: host,
port: bsPort,
pathname: path,
}),
ws: true,
logLevel: 'silent',
}) as any,
];
bsOptions.middleware = [
createProxyMiddleware(defaultSocketIoPath, {
target: url.format({
protocol: 'http',
hostname: host,
port: bsPort,
pathname: path,
}),
ws: true,
logLevel: 'silent',
}) as any,
];
}
}

Expand Down

0 comments on commit a279fa6

Please sign in to comment.