Skip to content

Commit 068ddf1

Browse files
committed
chore: update README and BrowserEchoScript to reflect new default route for Next.js integration
1 parent 9368bf6 commit 068ddf1

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type BrowserLogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
4747

4848
interface BrowserEchoOptions {
4949
enabled?: boolean; // default: true (dev only)
50-
route?: `/${string}`; // default: '/__client-logs'
50+
route?: `/${string}`; // default: '/api/client-logs' (Next), '/__client-logs' (others)
5151
include?: BrowserLogLevel[]; // default: ['log','info','warn','error','debug']
5252
preserveConsole?: boolean; // default: true (also keep logging in the browser)
5353
tag?: string; // default: '[browser]'
@@ -75,7 +75,7 @@ interface BrowserEchoOptions {
7575

7676
* Vite: ensure plugin is added and either `index.html` exists or you import the virtual module manually.
7777
* Nuxt: confirm the module is in `modules[]` and you’re in dev mode.
78-
* Next: make sure `app/__client-logs/route.ts` is exported and `<BrowserEchoScript />` is rendered in `<head>`.
78+
* Next: make sure `app/api/client-logs/route.ts` is exported and `<BrowserEchoScript />` is rendered in `<head>`.
7979

8080
* Endpoint 404
8181

packages/next/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type BrowserLogLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
4242

4343
interface BrowserEchoScriptProps {
4444
enabled?: boolean; // default: true (dev only)
45-
route?: `/${string}`; // default: '/__client-logs'
45+
route?: `/${string}`; // default: '/api/client-logs'
4646
include?: BrowserLogLevel[]; // default: ['log','info','warn','error','debug']
4747
preserveConsole?: boolean; // default: true (also keep logging in the browser)
4848
tag?: string; // default: '[browser]'
@@ -142,7 +142,7 @@ Forward logs to your terminal via a dedicated route:
142142
export { POST, runtime, dynamic } from '@browser-echo/next/route';
143143
```
144144

145-
- Route defaults to `/__client-logs` but works better as `/api/client-logs` in Next.js 15+
145+
- Default route is `/api/client-logs` (works best in Next.js 15+)
146146
- We set `runtime = 'nodejs'` and `dynamic = 'force-dynamic'` to ensure it runs on Node and isn't cached
147147

148148
## Usage Example
@@ -210,7 +210,7 @@ This package depends on [@browser-echo/core](https://github.com/instructa/browse
210210

211211
## Troubleshooting
212212

213-
- **No logs appear**: Make sure `app/__client-logs/route.ts` is exported and `<BrowserEchoScript />` is rendered in `<head>`
213+
- **No logs appear**: Make sure `app/api/client-logs/route.ts` is exported and `<BrowserEchoScript />` is rendered in `<head>`
214214
- **Endpoint 404**: Verify your route file path matches the script's `route` prop
215215
- **Too noisy**: Limit to `include: ['warn','error']` and use `stackMode: 'condensed'`
216216

packages/next/src/BrowserEchoScript.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export default function BrowserEchoScript(props: BrowserEchoScriptProps): JSX.El
2121
return <></>;
2222
}
2323

24-
const route = props.route ?? '/__client-logs';
24+
// Default to the conventional Next.js API route path
25+
const route = props.route ?? '/api/client-logs';
2526
const include = JSON.stringify(props.include ?? ['log','info','warn','error','debug']);
2627
const preserve = props.preserveConsole ?? true;
2728
const tag = props.tag ?? '[browser]';

packages/next/src/setup.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
2-
import { existsSync, mkdirSync, writeFileSync } from 'fs';
3-
import { join } from 'path';
2+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
3+
import { join } from 'node:path';
44

55
const ROUTE_CONTENT = `export { POST, runtime, dynamic } from '@browser-echo/next/route';
66
`;
@@ -56,7 +56,11 @@ export function setup(projectRoot = process.cwd()) {
5656
`);
5757
}
5858

59-
// Run if called directly
60-
if (require.main === module) {
59+
// Run if called directly (ESM-safe)
60+
const isDirectRun = typeof process !== 'undefined'
61+
&& Array.isArray(process.argv)
62+
&& (process.argv[1]?.endsWith('setup.mjs') || process.argv[1]?.endsWith('setup.js'));
63+
64+
if (isDirectRun) {
6165
setup();
6266
}

0 commit comments

Comments
 (0)