Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/next-dashboard-route.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@workflow/next': minor
---

Add `/_workflow` route in dev mode that opens the workflow observability dashboard.
1 change: 1 addition & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@workflow/builders": "workspace:*",
"@workflow/core": "workspace:*",
"@workflow/swc-plugin": "workspace:*",
"@workflow/web": "workspace:*",
"semver": "catalog:",
"watchpack": "2.5.1"
},
Expand Down
47 changes: 47 additions & 0 deletions packages/next/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ const workflowSerdeComputedPropertyPattern =
const PSEUDO_EXTERNAL_PACKAGES = new Set(['server-only', 'client-only']);
const warnedAutoRemovedServerExternalPackages = new Set<string>();

let dashboardServerPromise: Promise<string> | undefined;

function ensureDashboardServer(): Promise<string> {
if (!dashboardServerPromise) {
dashboardServerPromise = (async () => {
const { startServer } = (await import('@workflow/web/server')) as {
startServer: (port?: number) => Promise<import('node:http').Server>;
};
const server = await startServer(0);
const address = server.address();
const port = typeof address === 'object' && address ? address.port : 3456;
return `http://localhost:${port}`;
})().catch((error: unknown) => {
dashboardServerPromise = undefined;
throw error;
});
}
return dashboardServerPromise;
}

interface WorkflowPatternMatch {
hasUseWorkflow: boolean;
hasUseStep: boolean;
Expand Down Expand Up @@ -629,6 +649,33 @@ export function withWorkflow(
process.env.WORKFLOW_NEXT_PRIVATE_BUILT = '1';
}

if (phase === 'phase-development-server') {
const dashboardUrl = await ensureDashboardServer().catch(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next.config can be loaded multiple times so would be good to have an env check like the process.env.WORKFLOW_NEXT_PRIVATE_BUILT above to ensure we only start this server once.

(error: unknown) => {
console.error('Failed to start workflow dashboard:', error);
return undefined;
}
);

if (dashboardUrl) {
const existingRedirects = nextConfig.redirects;
nextConfig.redirects = async () => {
const userRedirects = existingRedirects
? await existingRedirects()
: [];
return [
...userRedirects,
{
source: '/_workflow',
destination: dashboardUrl,
permanent: false,
basePath: false,
},
];
};
}
}

return nextConfig;
};
}
15 changes: 5 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading