@frontman-ai/nextjs 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -5
- package/dist/cli.js +87 -42
- package/dist/index.js +1 -1
- package/dist/instrumentation.js +15 -16
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -130,10 +130,11 @@ export async function register() {
|
|
|
130
130
|
|
|
131
131
|
If you already have `middleware.ts`, `proxy.ts`, or `instrumentation.ts` files, the installer will show you manual integration steps. Here's how to add Frontman to existing files:
|
|
132
132
|
|
|
133
|
-
### Existing middleware.ts
|
|
133
|
+
### Existing middleware.ts (Next.js 15)
|
|
134
134
|
|
|
135
135
|
```typescript
|
|
136
136
|
import { createMiddleware } from '@frontman-ai/nextjs';
|
|
137
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
137
138
|
// ... your other imports
|
|
138
139
|
|
|
139
140
|
const frontman = createMiddleware({
|
|
@@ -141,11 +142,11 @@ const frontman = createMiddleware({
|
|
|
141
142
|
});
|
|
142
143
|
|
|
143
144
|
export async function middleware(req: NextRequest) {
|
|
144
|
-
// Add Frontman handler first
|
|
145
|
+
// Add Frontman handler first - it will handle /__frontman/* routes
|
|
145
146
|
const response = await frontman(req);
|
|
146
147
|
if (response) return response;
|
|
147
148
|
|
|
148
|
-
// ... your existing middleware logic
|
|
149
|
+
// ... your existing middleware logic below
|
|
149
150
|
return NextResponse.next();
|
|
150
151
|
}
|
|
151
152
|
|
|
@@ -155,17 +156,59 @@ export const config = {
|
|
|
155
156
|
};
|
|
156
157
|
```
|
|
157
158
|
|
|
159
|
+
### Existing proxy.ts (Next.js 16+)
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { createMiddleware } from '@frontman-ai/nextjs';
|
|
163
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
164
|
+
// ... your other imports
|
|
165
|
+
|
|
166
|
+
const frontman = createMiddleware({
|
|
167
|
+
host: 'api.frontman.sh', // or 'frontman.local:4000' for local development
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
export function proxy(req: NextRequest): NextResponse | Promise<NextResponse> {
|
|
171
|
+
// Add Frontman handler first - it will handle /__frontman/* routes
|
|
172
|
+
if (req.nextUrl.pathname.startsWith('/__frontman')) {
|
|
173
|
+
return frontman(req) || NextResponse.next();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ... your existing proxy logic below
|
|
177
|
+
return NextResponse.next();
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
158
181
|
### Existing instrumentation.ts
|
|
159
182
|
|
|
183
|
+
If you **don't have OpenTelemetry** set up yet:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
export async function register() {
|
|
187
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
188
|
+
const { NodeSDK } = await import('@opentelemetry/sdk-node');
|
|
189
|
+
const { setup } = await import('@frontman-ai/nextjs/Instrumentation');
|
|
190
|
+
const [logProcessor, spanProcessor] = setup();
|
|
191
|
+
|
|
192
|
+
new NodeSDK({
|
|
193
|
+
logRecordProcessors: [logProcessor],
|
|
194
|
+
spanProcessors: [spanProcessor],
|
|
195
|
+
}).start();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ... your existing instrumentation logic
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
If you **already have OpenTelemetry** set up, add the Frontman processors to your existing configuration:
|
|
203
|
+
|
|
160
204
|
```typescript
|
|
161
205
|
export async function register() {
|
|
162
206
|
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
163
207
|
const { setup } = await import('@frontman-ai/nextjs/Instrumentation');
|
|
164
208
|
const [logProcessor, spanProcessor] = setup();
|
|
165
209
|
|
|
166
|
-
// Add to your existing NodeSDK configuration:
|
|
167
210
|
new NodeSDK({
|
|
168
|
-
// ... your existing config
|
|
211
|
+
// ... your existing OTEL config
|
|
169
212
|
logRecordProcessors: [logProcessor, ...yourExistingLogProcessors],
|
|
170
213
|
spanProcessors: [spanProcessor, ...yourExistingSpanProcessors],
|
|
171
214
|
}).start();
|
package/dist/cli.js
CHANGED
|
@@ -168,71 +168,116 @@ function instrumentationTemplate() {
|
|
|
168
168
|
}
|
|
169
169
|
`;
|
|
170
170
|
}
|
|
171
|
-
function middlewareManualSetup(fileName) {
|
|
171
|
+
function middlewareManualSetup(fileName, host) {
|
|
172
172
|
return `
|
|
173
|
-
|
|
173
|
+
` + fileName + ` already exists and requires manual modification.
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
Add the following to your ` + fileName + `:
|
|
176
|
+
|
|
177
|
+
1. Add import at the top of the file:
|
|
176
178
|
|
|
177
|
-
1. Import at the top of the file:
|
|
178
179
|
import { createMiddleware } from '@frontman-ai/nextjs';
|
|
179
180
|
|
|
180
|
-
2. Create the middleware instance:
|
|
181
|
+
2. Create the middleware instance (after imports):
|
|
182
|
+
|
|
181
183
|
const frontman = createMiddleware({
|
|
182
|
-
host: '
|
|
184
|
+
host: '` + host + `',
|
|
183
185
|
});
|
|
184
186
|
|
|
185
|
-
3. In your middleware function, add
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
3. In your middleware function, add at the beginning:
|
|
188
|
+
|
|
189
|
+
export async function middleware(req: NextRequest) {
|
|
190
|
+
// Add Frontman handler first
|
|
191
|
+
const response = await frontman(req);
|
|
192
|
+
if (response) return response;
|
|
193
|
+
|
|
194
|
+
// ... your existing middleware logic
|
|
195
|
+
}
|
|
188
196
|
|
|
189
|
-
4.
|
|
190
|
-
matcher: ['/__frontman/:path*', ...yourExistingMatchers],
|
|
197
|
+
4. Update your matcher config to include Frontman routes:
|
|
191
198
|
|
|
192
|
-
|
|
199
|
+
export const config = {
|
|
200
|
+
matcher: ['/__frontman/:path*', ...yourExistingMatchers],
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
For full documentation, see: https://frontman.sh/docs/nextjs
|
|
193
204
|
`;
|
|
194
205
|
}
|
|
195
|
-
function
|
|
206
|
+
function proxyManualSetup(fileName, host) {
|
|
196
207
|
return `
|
|
197
|
-
|
|
208
|
+
` + fileName + ` already exists and requires manual modification.
|
|
198
209
|
|
|
199
|
-
|
|
210
|
+
Add the following to your ` + fileName + `:
|
|
200
211
|
|
|
201
|
-
1.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const [logProcessor, spanProcessor] = setup();
|
|
212
|
+
1. Add import at the top of the file:
|
|
213
|
+
|
|
214
|
+
import { createMiddleware } from '@frontman-ai/nextjs';
|
|
205
215
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
216
|
+
2. Create the middleware instance (after imports):
|
|
217
|
+
|
|
218
|
+
const frontman = createMiddleware({
|
|
219
|
+
host: '` + host + `',
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
3. In your proxy function, add at the beginning:
|
|
223
|
+
|
|
224
|
+
export function proxy(req: NextRequest): NextResponse | Promise<NextResponse> {
|
|
225
|
+
// Add Frontman handler first
|
|
226
|
+
if (req.nextUrl.pathname.startsWith('/__frontman')) {
|
|
227
|
+
return frontman(req) || NextResponse.next();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// ... your existing proxy logic
|
|
209
231
|
}
|
|
210
232
|
|
|
211
|
-
For full documentation, see: https://frontman.
|
|
233
|
+
For full documentation, see: https://frontman.sh/docs/nextjs
|
|
212
234
|
`;
|
|
213
235
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
Error: proxy.ts already exists and requires manual modification.
|
|
236
|
+
function instrumentationManualSetup(fileName) {
|
|
237
|
+
return `
|
|
238
|
+
` + fileName + ` already exists and requires manual modification.
|
|
218
239
|
|
|
219
|
-
|
|
240
|
+
Add the following to your ` + fileName + `:
|
|
220
241
|
|
|
221
|
-
1.
|
|
222
|
-
import { createMiddleware } from '@frontman-ai/nextjs';
|
|
242
|
+
1. If you DON'T have OpenTelemetry set up yet, add inside register():
|
|
223
243
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
244
|
+
export async function register() {
|
|
245
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
246
|
+
const { NodeSDK } = await import('@opentelemetry/sdk-node');
|
|
247
|
+
const { setup } = await import('@frontman-ai/nextjs/Instrumentation');
|
|
248
|
+
const [logProcessor, spanProcessor] = setup();
|
|
228
249
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
250
|
+
new NodeSDK({
|
|
251
|
+
logRecordProcessors: [logProcessor],
|
|
252
|
+
spanProcessors: [spanProcessor],
|
|
253
|
+
}).start();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// ... your existing instrumentation logic
|
|
232
257
|
}
|
|
233
258
|
|
|
234
|
-
|
|
235
|
-
|
|
259
|
+
2. If you ALREADY have OpenTelemetry set up, add the Frontman processors:
|
|
260
|
+
|
|
261
|
+
export async function register() {
|
|
262
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
263
|
+
const { setup } = await import('@frontman-ai/nextjs/Instrumentation');
|
|
264
|
+
const [logProcessor, spanProcessor] = setup();
|
|
265
|
+
|
|
266
|
+
new NodeSDK({
|
|
267
|
+
// Add Frontman processors to your existing configuration:
|
|
268
|
+
logRecordProcessors: [logProcessor, ...yourExistingLogProcessors],
|
|
269
|
+
spanProcessors: [spanProcessor, ...yourExistingSpanProcessors],
|
|
270
|
+
// ... your other OTEL config
|
|
271
|
+
}).start();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
For full documentation, see: https://frontman.sh/docs/nextjs
|
|
276
|
+
`;
|
|
277
|
+
}
|
|
278
|
+
var ErrorMessages = {
|
|
279
|
+
middlewareManualSetup,
|
|
280
|
+
proxyManualSetup,
|
|
236
281
|
instrumentationManualSetup
|
|
237
282
|
};
|
|
238
283
|
function fileCreated(fileName) {
|
|
@@ -253,7 +298,7 @@ Next steps:
|
|
|
253
298
|
2. Open your browser to: http://localhost:3000/__frontman
|
|
254
299
|
3. Your app is now connected to: ` + host + `
|
|
255
300
|
|
|
256
|
-
For documentation, visit: https://frontman.
|
|
301
|
+
For documentation, visit: https://frontman.sh/docs
|
|
257
302
|
`;
|
|
258
303
|
}
|
|
259
304
|
var SuccessMessages = {
|
|
@@ -303,7 +348,7 @@ async function handleMiddleware(projectDir, host, existingFile, dryRun) {
|
|
|
303
348
|
TAG: "Ok",
|
|
304
349
|
_0: {
|
|
305
350
|
TAG: "ManualEditRequired",
|
|
306
|
-
_0: ErrorMessages.middlewareManualSetup(fileName)
|
|
351
|
+
_0: ErrorMessages.middlewareManualSetup(fileName, host)
|
|
307
352
|
}
|
|
308
353
|
};
|
|
309
354
|
}
|
|
@@ -390,7 +435,7 @@ async function handleProxy(projectDir, host, existingFile, dryRun) {
|
|
|
390
435
|
TAG: "Ok",
|
|
391
436
|
_0: {
|
|
392
437
|
TAG: "ManualEditRequired",
|
|
393
|
-
_0: ErrorMessages.proxyManualSetup
|
|
438
|
+
_0: ErrorMessages.proxyManualSetup(fileName, host)
|
|
394
439
|
}
|
|
395
440
|
};
|
|
396
441
|
}
|
package/dist/index.js
CHANGED
|
@@ -121,7 +121,7 @@ function make(isDevOpt, basePathOpt, serverNameOpt, serverVersionOpt, hostOpt, c
|
|
|
121
121
|
let projectRoot$1 = getOr(orElse(projectRoot, orElse(process.env["PROJECT_ROOT"], process.env["PWD"])), ".");
|
|
122
122
|
let sourceRoot$1 = getOr(sourceRoot, projectRoot$1);
|
|
123
123
|
let baseUrl = process.env["FRONTMAN_CLIENT_URL"];
|
|
124
|
-
let clientUrl$1 = getOr(clientUrl, baseUrl !== void 0 ? baseUrl + `?clientName=nextjs&host=` + host$1 : isDev$1 ? `http://localhost:5173/src/Main.res.mjs?clientName=nextjs&host=` + host$1 : `https://frontman.
|
|
124
|
+
let clientUrl$1 = getOr(clientUrl, baseUrl !== void 0 ? baseUrl + `?clientName=nextjs&host=` + host$1 : isDev$1 ? `http://localhost:5173/src/Main.res.mjs?clientName=nextjs&host=` + host$1 : `https://frontman.sh/frontman.es.js?clientName=nextjs&host=` + host$1);
|
|
125
125
|
return {
|
|
126
126
|
isDev: isDev$1,
|
|
127
127
|
basePath: basePath$1,
|
package/dist/instrumentation.js
CHANGED
|
@@ -46,23 +46,22 @@ function initialize(transport) {
|
|
|
46
46
|
if (initialized.contents) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"frontman-nextjs"
|
|
56
|
-
]])
|
|
49
|
+
let scope_tags = Object.fromEntries([[
|
|
50
|
+
"frontman.library",
|
|
51
|
+
"frontman-nextjs"
|
|
52
|
+
]]);
|
|
53
|
+
let scope = {
|
|
54
|
+
tags: scope_tags
|
|
57
55
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
{
|
|
57
|
+
Nextjs.init({
|
|
58
|
+
dsn,
|
|
59
|
+
environment: process.env.NODE_ENV || "development",
|
|
60
|
+
release: process.env.npm_package_version || "unknown",
|
|
61
|
+
sampleRate: 1,
|
|
62
|
+
initialScope: scope
|
|
63
|
+
});
|
|
64
|
+
}
|
|
66
65
|
initialized.contents = true;
|
|
67
66
|
}
|
|
68
67
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontman-ai/nextjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Next.js integration for Frontman - AI-powered development tools and observability",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"./Instrumentation": "./dist/instrumentation.js"
|
|
10
10
|
},
|
|
11
11
|
"bin": {
|
|
12
|
-
"frontman-nextjs": "./dist/cli.js"
|
|
12
|
+
"frontman-nextjs": "./dist/cli.js",
|
|
13
|
+
"nextjs": "./dist/cli.js"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|
|
15
16
|
"frontman",
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
"url": "https://github.com/frontman-ai/frontman.git",
|
|
29
30
|
"directory": "libs/frontman-nextjs"
|
|
30
31
|
},
|
|
31
|
-
"homepage": "https://frontman.
|
|
32
|
+
"homepage": "https://frontman.sh",
|
|
32
33
|
"bugs": {
|
|
33
34
|
"url": "https://github.com/frontman-ai/frontman/issues"
|
|
34
35
|
},
|