### Run Development Server with Different Package Managers (Bash) Source: https://github.com/1weiho/next-lens/blob/main/packages/next-lens/tests/fixtures/mock-next-app/README.md Commands to start the Next.js development server. These commands are executed in a bash environment and leverage different package managers (npm, yarn, pnpm, bun). The output of this command is the running development server accessible via a local URL. ```bash npm run dev # or yarn dev # or pnpm dev # or bun dev ``` -------------------------------- ### Install and Run next-lens CLI Source: https://github.com/1weiho/next-lens/blob/main/packages/next-lens/README.md Demonstrates how to install and run the next-lens CLI tool. It can be executed directly using npx and accepts an optional target directory argument. ```bash npx next-lens@latest [command] [target-directory] ``` -------------------------------- ### MCP Usage Example for Next.js Route Inspection Source: https://context7.com/1weiho/next-lens/llms.txt Demonstrates how an AI assistant can leverage MCP to call next-lens tools for common Next.js development tasks, such as finding specific API endpoints or listing pages that lack error boundaries. ```typescript // AI assistant using MCP can call: // "Find all POST endpoints in the API" await mcp.callTool('api-search', { search: '/api', method: 'POST' }) // "Show me pages without error boundaries" const pages = await mcp.callTool('page-list', {}) const noError = pages.filter(p => p.error === 'missing') // "List user-related routes" const apiRoutes = await mcp.callTool('api-search', { search: '/user' }) const pageRoutes = await mcp.callTool('page-search', { search: '/user' }) ``` -------------------------------- ### Get API Routes Source: https://context7.com/1weiho/next-lens/llms.txt Retrieves a list of all API routes defined in the project, including the file path, supported HTTP methods, and the route path. ```APIDOC ## GET /api/routes ### Description Retrieves a list of all API routes defined in the project, including the file path, supported HTTP methods, and the route path. ### Method GET ### Endpoint `/api/routes` (Web Inspector) ### Parameters None ### Request Example ```bash curl http://localhost:9453/api/routes ``` ### Response #### Success Response (200) - **Array of API Route Objects**: Contains details for each API route. #### API Route Object Structure - **file** (string) - The relative path to the API route file. - **methods** (Array) - An array of HTTP methods supported by the route (e.g., ['GET', 'POST']). - **path** (string) - The URL path for the API route, potentially with parameter placeholders (e.g., `/api/users/:id`). #### Response Example ```json [ { "file": "app/api/users/[id]/route.ts", "methods": ["GET", "PUT", "DELETE"], "path": "/api/users/:id" } ] ``` ``` -------------------------------- ### MCP Integration Source: https://context7.com/1weiho/next-lens/llms.txt Details on configuring and using the Multi-Command Protocol (MCP) for interacting with next-lens tools, including available commands and usage examples. ```APIDOC ## MCP Integration ### Description Details on configuring and using the Multi-Command Protocol (MCP) for interacting with next-lens tools, including available commands and usage examples. ### Configuration Add the following to your `mcp.json` or equivalent configuration: ```json { "mcpServers": { "next-lens": { "command": "npx", "args": ["next-lens@latest", "mcp"] } } } ``` ### Available MCP Tools - **api-list** - **Description**: Lists all API routes. - **Arguments**: - `targetDirectory` (string, optional): The directory to scan for API routes. - `method` (string, optional): Filters API routes by HTTP method (e.g., 'GET', 'POST'). - **Returns**: Array of `{ file, methods[], path }`. - **page-list** - **Description**: Lists all page routes. - **Arguments**: - `targetDirectory` (string, optional): The directory to scan for page routes. - **Returns**: Array of `{ file, path, loading, error, loadingPath?, errorPath? }`. - **api-search** - **Description**: Searches API routes by path substring. - **Arguments**: - `targetDirectory` (string, optional): The directory to scan. - `search` (string, required): The path substring to search for. - `method` (string, optional): Filters by HTTP method. - **Returns**: Filtered array of matching API routes. - **page-search** - **Description**: Searches page routes by path substring. - **Arguments**: - `targetDirectory` (string, optional): The directory to scan. - `search` (string, required): The path substring to search for. - **Returns**: Filtered array of matching page routes. ### MCP Usage Example ```typescript // Assuming 'mcp' is an instance of the MCP client // Find all POST endpoints in the API const postEndpoints = await mcp.callTool('api-search', { search: '/api', method: 'POST' }); // Show me pages without error boundaries const allPages = await mcp.callTool('page-list', {}); const pagesWithoutError = allPages.filter(p => p.error === 'missing'); // List user-related routes (both API and pages) const userRoutes = await mcp.callTool('api-search', { search: '/user' }); const userPages = await mcp.callTool('page-search', { search: '/user' }); ``` ``` -------------------------------- ### Integrate React-Specific ESLint Rules with TypeScript Source: https://github.com/1weiho/next-lens/blob/main/apps/inspector/README.md This JavaScript code snippet shows how to integrate `eslint-plugin-react-x` and `eslint-plugin-react-dom` into your ESLint configuration for a React + TypeScript project. It enables recommended lint rules specifically for React and React DOM components. Ensure these plugins are installed and TSconfig files are correctly referenced. ```javascript // eslint.config.js import reactX from 'eslint-plugin-react-x' import reactDom from 'eslint-plugin-react-dom' export default defineConfig([ globalIgnores(['dist']), { files: ['**/*.{ts,tsx}'] extends: [ // Other configs... // Enable lint rules for React reactX.configs['recommended-typescript'], // Enable lint rules for React DOM reactDom.configs.recommended, ], languageOptions: { parserOptions: { project: ['./tsconfig.node.json', './tsconfig.app.json'], tsconfigRootDir: import.meta.dirname, }, // other options... }, }, ]) ``` -------------------------------- ### Collect Next.js Project Information with TypeScript Source: https://context7.com/1weiho/next-lens/llms.txt Gathers essential project details such as the Next.js version, React version, package manager, and package.json contents. This utility is useful for validating project setup and compatibility. It uses the 'next-lens/commands/info' module. ```typescript import { collectInsights, type ProjectInsights } from 'next-lens/commands/info' // Gather framework and runtime details const insights: ProjectInsights = await collectInsights('/path/to/nextjs-app') // ProjectInsights structure: // { // root: "/absolute/path/to/project", // manifest: PackageJson | null, // packageManager: "pnpm (lockfile)" | "npm (lockfile)" | null, // nextVersion: "15.0.2" | null, // reactVersion: "18.3.1" | null // } // Validate Next.js version if (insights.nextVersion) { const major = parseInt(insights.nextVersion.split('.')[0]) if (major >= 13) { console.log('✓ Using App Router compatible Next.js version') } else { console.warn('⚠️ App Router requires Next.js 13+') } } // Check package manager console.log(`Package manager: ${insights.packageManager || 'unknown'}`) // Access package.json data if (insights.manifest) { console.log(`Project: ${insights.manifest.name}`) console.log(`Version: ${insights.manifest.version}`) }) ``` -------------------------------- ### Web Inspector API: GET /api/pages Source: https://context7.com/1weiho/next-lens/llms.txt An HTTP GET endpoint for the Web Inspector API that retrieves a list of all page routes in a Next.js application. The response includes details about each page's file, path, and the status of its co-located or inherited loading and error states. ```bash # List all page routes curl http://localhost:9453/api/pages # Response: [ { "file": "app/dashboard/page.tsx", "path": "/dashboard", "loading": "co-located", "error": "inherited", "loadingPath": "app/dashboard/loading.tsx", "errorPath": "app/error.tsx" } ] ``` -------------------------------- ### Get Page Routes Source: https://context7.com/1weiho/next-lens/llms.txt Retrieves a list of all page routes within a Next.js application, providing details about their structure and associated loading/error states. ```APIDOC ## Get Page Routes ### Description Retrieves a list of all page routes within a Next.js application, providing details about their structure and associated loading/error states. ### Method GET ### Endpoint `/api/pages` (Web Inspector) ### Parameters None ### Request Example ```bash curl http://localhost:9453/api/pages ``` ### Response #### Success Response (200) - **Array of PageInfo Objects**: Contains details for each page route. #### PageInfo Structure - **file** (string) - The relative path to the page file. - **path** (string) - The URL path for the page. - **loading** (string) - Indicates the loading state strategy ('co-located', 'inherited', 'missing'). - **error** (string) - Indicates the error handling strategy ('co-located', 'inherited', 'missing'). - **loadingPath?** (string) - Optional path to the co-located loading file. - **errorPath?** (string) - Optional path to the co-located error file. #### Response Example ```json [ { "file": "app/dashboard/page.tsx", "path": "/dashboard", "loading": "co-located", "error": "inherited", "loadingPath": "app/dashboard/loading.tsx", "errorPath": "app/error.tsx" } ] ``` ``` -------------------------------- ### Web Inspector API: GET /api/routes Source: https://context7.com/1weiho/next-lens/llms.txt An HTTP GET endpoint provided by the Web Inspector API to list all API routes within a Next.js application. It returns an array of objects, each detailing the file path, supported HTTP methods, and the route's URL pattern. ```bash # List all API routes curl http://localhost:9453/api/routes # Response: [ { "file": "app/api/users/[id]/route.ts", "methods": ["GET", "PUT", "DELETE"], "path": "/api/users/:id" } ] ``` -------------------------------- ### Configure ESLint for Type-Aware Lint Rules in TypeScript Source: https://github.com/1weiho/next-lens/blob/main/apps/inspector/README.md This JavaScript code snippet demonstrates how to expand ESLint configuration for a React + TypeScript + Vite project to enable type-aware lint rules. It requires @typescript-eslint/eslint-plugin and specifies project configurations for type checking. Ensure 'tsconfig.node.json' and 'tsconfig.app.json' exist. ```javascript export default defineConfig([ globalIgnores(['dist']), { files: ['**/*.{ts,tsx}'] extends: [ // Other configs... // Remove tseslint.configs.recommended and replace with this tseslint.configs.recommendedTypeChecked, // Alternatively, use this for stricter rules tseslint.configs.strictTypeChecked, // Optionally, add this for stylistic rules tseslint.configs.stylisticTypeChecked, // Other configs... ], languageOptions: { parserOptions: { project: ['./tsconfig.node.json', './tsconfig.app.json'], tsconfigRootDir: import.meta.dirname, }, // other options... }, }, ]) ``` -------------------------------- ### Get Next.js Page Routes with TypeScript Source: https://context7.com/1weiho/next-lens/llms.txt Fetches and analyzes all page routes within a Next.js application. It helps identify pages missing error handling or those with co-located loading states. Requires the 'next-lens/lib/page-routes' module. ```typescript import { getPageRoutes, type PageInfo } from 'next-lens/lib/page-routes' // List all page routes const pages: PageInfo[] = await getPageRoutes('/path/to/nextjs-app') // PageInfo structure: // { // file: "app/dashboard/page.tsx", // path: "/dashboard", // loading: "co-located" | "inherited" | "missing", // error: "co-located" | "inherited" | "missing", // loadingPath?: "app/dashboard/loading.tsx", // errorPath?: "app/error.tsx" // } // Find pages without error boundaries const pagesWithoutError = pages.filter(page => page.error === 'missing') pagesWithoutError.forEach(page => { console.log(`⚠️ ${page.path} is missing error handling`) console.log(` Add error.tsx to ${page.file.replace('/page.tsx', '')}`) }) // Find pages with co-located loading states const loadingPages = pages.filter(page => page.loading === 'co-located') console.log(`${loadingPages.length} pages have loading UI`) // Check for inherited boundaries pages.forEach(page => { if (page.loading === 'inherited') { console.log(`${page.path} inherits loading from ${page.loadingPath}`) } if (page.error === 'inherited') { console.log(`${page.path} inherits error from ${page.errorPath}`) } }) ``` -------------------------------- ### Get API Routes Programmatically (TypeScript) Source: https://context7.com/1weiho/next-lens/llms.txt Retrieves API routes from a Next.js project using the programmatic API in TypeScript. Supports listing all routes or filtering by specific HTTP methods. The function returns route information including file path, HTTP methods, and URL path. Requires the 'next-lens/lib/api-routes' import. ```typescript import { getApiRoutes, type RouteInfo } from 'next-lens/lib/api-routes' // List all API routes const routes: RouteInfo[] = await getApiRoutes('/path/to/nextjs-app') // Filter by HTTP method const getRoutes = await getApiRoutes('/path/to/nextjs-app', 'GET') const postRoutes = await getApiRoutes(null, 'POST') // null = current directory // RouteInfo structure: // { // file: "app/api/users/[id]/route.ts", // methods: ["GET", "PUT", "DELETE"], // path: "/api/users/:id" // } // Process routes routes.forEach(route => { console.log(`${route.methods.join('|')} ${route.path}`) console.log(` Source: ${route.file}`) // Check for dynamic segments if (route.path.includes(':')) { console.log(` Has dynamic parameters`) } // Check for catch-all routes if (route.path.includes('*')) { console.log(` Catch-all route`) } }) // Supported HTTP methods: // GET, HEAD, OPTIONS, POST, PUT, PATCH, DELETE ``` -------------------------------- ### Display Project Information via CLI Source: https://context7.com/1weiho/next-lens/llms.txt Shows framework and runtime versions for a Next.js project using the next-lens CLI. It can scan the current directory or a specified project path. The output includes versions for Next.js, React, next-lens, Node, and the package manager. ```bash npx next-lens@latest info npx next-lens@latest info ./my-nextjs-app ``` -------------------------------- ### POST /api/pages/loading Source: https://context7.com/1weiho/next-lens/llms.txt Creates a `loading.tsx` file for a specified page. This helps in implementing loading states for page transitions. ```APIDOC ## POST /api/pages/loading ### Description Creates a `loading.tsx` file for a specified page to manage loading states. ### Method POST ### Endpoint /api/pages/loading ### Parameters #### Request Body - **file** (string) - Required - The path to the page file for which to create the loading component (e.g., `app/dashboard/page.tsx`). ### Request Example ```json { "file": "app/dashboard/page.tsx" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **file** (string) - The path to the newly created loading file (e.g., `app/dashboard/loading.tsx`). #### Error Response - **error** (string) - Message indicating if the loading file already exists. #### Response Example (Success) ```json { "success": true, "file": "app/dashboard/loading.tsx" } ``` #### Response Example (Error) ```json { "error": "loading.tsx already exists at app/dashboard/loading.tsx" } ``` ``` -------------------------------- ### POST /api/open-file Source: https://context7.com/1weiho/next-lens/llms.txt Opens a specified file in the default IDE, optionally navigating to a specific line number. ```APIDOC ## POST /api/open-file ### Description Opens a specified file in the default IDE, optionally navigating to a specific line number. It uses the `launch-editor` package to detect and open the file in editors like VS Code, Cursor, Atom, Sublime Text, WebStorm, etc. ### Method POST ### Endpoint /api/open-file ### Parameters #### Request Body - **file** (string) - Required - The path to the file to open (e.g., `app/dashboard/page.tsx`). - **line** (number) - Optional - The specific line number to navigate to within the file. ### Request Example ```json { "file": "app/dashboard/page.tsx", "line": 42 } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### POST /api/routes/methods Source: https://context7.com/1weiho/next-lens/llms.txt Adds a new HTTP method to an existing API route file. ```APIDOC ## POST /api/routes/methods ### Description Adds a new HTTP method to an existing API route file. ### Method POST ### Endpoint `/api/routes/methods` (Web Inspector) ### Parameters #### Request Body - **file** (string) - Required - The relative path to the API route file. - **method** (string) - Required - The HTTP method to add (e.g., 'POST', 'PATCH'). ### Request Example ```bash curl -X POST http://localhost:9453/api/routes/methods \ -H "Content-Type: application/json" \ -d '{ "file": "app/api/users/route.ts", "method": "POST" }' ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Create Loading UI File for a Page Source: https://context7.com/1weiho/next-lens/llms.txt Automatically generates a `loading.tsx` file for a specified page. This helps in implementing loading states for Next.js pages. The command returns success status and the path of the created file, or an error if the file already exists. ```bash curl -X POST http://localhost:9453/api/pages/loading \ -H "Content-Type: application/json" \ -d '{ "file": "app/dashboard/page.tsx" }' ``` -------------------------------- ### Open File in IDE Source: https://context7.com/1weiho/next-lens/llms.txt Opens a specified file in the default IDE, optionally at a specific line number. This facilitates quick navigation and editing of project files. It utilizes the `launch-editor` package to detect and open files in various IDEs. ```bash curl -X POST http://localhost:9453/api/open-file \ -H "Content-Type: application/json" \ -d '{ "file": "app/dashboard/page.tsx", "line": 42 }' ``` -------------------------------- ### Launch Web Inspector via CLI Source: https://context7.com/1weiho/next-lens/llms.txt Launches the next-lens web-based inspector UI. It can be run on a default or custom port, with options to prevent auto-opening the browser or to enable development mode with Hot Module Replacement (HMR) by proxying to Vite. The inspector provides a UI to manage routes. ```bash npx next-lens@latest web npx next-lens@latest web --port 3000 npx next-lens@latest web --no-open npx next-lens@latest web --dev --vite-port 5173 ``` -------------------------------- ### List Page Routes via CLI Source: https://context7.com/1weiho/next-lens/llms.txt Lists all page routes within a Next.js project directory using the next-lens CLI. It displays route paths, state UI coverage (loading/error boundaries), and source files. Supports specifying a project directory. ```bash npx next-lens@latest page:list npx next-lens@latest page:list ./my-nextjs-app ``` -------------------------------- ### List API Routes via CLI Source: https://context7.com/1weiho/next-lens/llms.txt Lists all API routes within a Next.js project directory using the next-lens CLI. Supports filtering by HTTP method and accepts a specific project directory path. It displays route methods, paths, and source files. ```bash npx next-lens@latest api:list npx next-lens@latest api:list ./my-nextjs-app npx next-lens@latest api:list --method GET npx next-lens@latest api:list -m POST ``` -------------------------------- ### MCP Tool Definitions for API and Page Lists Source: https://context7.com/1weiho/next-lens/llms.txt Describes available MCP tools for interacting with Next.js applications, including listing and searching API routes and page routes. Each tool specifies its name, required arguments, and the structure of its return value. ```typescript // Tool: api-list // List all API routes { "name": "api-list", "arguments": { "targetDirectory": "/path/to/project", // optional "method": "GET" // optional, filters by HTTP method } } // Returns: Array of { file, methods[], path } // Tool: page-list // List all page routes { "name": "page-list", "arguments": { "targetDirectory": "/path/to/project" // optional } } // Returns: Array of { file, path, loading, error, loadingPath?, errorPath? } // Tool: api-search // Search API routes by path { "name": "api-search", "arguments": { "targetDirectory": "/path/to/project", // optional "search": "/users", // required, path substring "method": "POST" // optional } } // Returns: Filtered array of matching routes // Tool: page-search // Search page routes by path { "name": "page-search", "arguments": { "targetDirectory": "/path/to/project", // optional "search": "/dashboard" // required, path substring } } // Returns: Filtered array of matching pages ``` -------------------------------- ### next-lens MCP Integration Configuration Source: https://github.com/1weiho/next-lens/blob/main/packages/next-lens/README.md Shows how to configure next-lens for integration with MCP (Most Common Patterns). This configuration allows IDEs or copilots to leverage next-lens insights. ```json { "mcpServers": { "next-lens": { "command": "npx", "args": ["next-lens@latest", "mcp"] } } } ``` -------------------------------- ### Create Error UI File for a Page Source: https://context7.com/1weiho/next-lens/llms.txt Automatically generates an `error.tsx` file for a specified page. This assists in implementing error handling for Next.js pages. The command confirms success and provides the path to the newly created error file. ```bash curl -X POST http://localhost:9453/api/pages/error \ -H "Content-Type: application/json" \ -d '{ "file": "app/dashboard/page.tsx" }' ``` -------------------------------- ### Route Path Transformation Source: https://context7.com/1weiho/next-lens/llms.txt Explains how Next.js file structure maps to Next-Lens path format, including handling dynamic segments, catch-all routes, and optional catch-all routes. ```APIDOC ## Route Path Transformation ### Dynamic Segments This section details the transformation of Next.js file structure conventions into the path format used by Next-Lens. #### Mapping Examples - `app/api/users/[id]/route.ts` → `/api/users/:id` - `app/blog/[slug]/page.tsx` → `/blog/:slug` - `app/shop/[category]/[product]/page.tsx` → `/shop/:category/:product` #### Catch-all and Optional Catch-all Routes - `app/api/files/[...parts]/route.ts` → `/api/files/:parts*` (catch-all) - `app/api/docs/[[...optional]]/route.ts` → `/api/docs/:optional*?` (optional catch-all) #### Static Segments and Route Groups - `app/about/page.tsx` → `/about` (static segment) - `app/(marketing)/page.tsx` → `/(marketing)` (route groups are noted but often filtered in route analysis) #### Utility Function Example ```typescript import { transformSegment } from 'next-lens/lib/utils' transformSegment('[id]') // → :id transformSegment('[slug]') // → :slug transformSegment('[...parts]') // → :parts* transformSegment('[[...optional]]') // → :optional*? transformSegment('static') // → static transformSegment('(group)') // → (group) ``` ### Route Group and Slot Handling Route groups denoted by parentheses `()` and parallel routes indicated by `@slot` are typically excluded when generating the final URL path for route analysis. #### Filtering Example Consider the following file structure: - `app/(marketing)/about/page.tsx` maps to the path `/about`. - `app/dashboard/@analytics/page.tsx` maps to the path `/dashboard`. - `app/(shop)/products/[id]/page.tsx` maps to `/products/:id`. ```typescript // Only actual route segments are included in the path transformation: const segments = ['app', '(marketing)', 'blog', '[slug]', 'page.tsx'] const filtered = segments.filter(shouldIncludeSegment) // Assuming shouldIncludeSegment filters out groups and slots // filtered → ['app', 'blog', '[slug]', 'page.tsx'] ``` ``` -------------------------------- ### Collect Project Information Source: https://context7.com/1weiho/next-lens/llms.txt Gathers essential information about a Next.js project, including its package manager, Next.js version, and React version. ```APIDOC ## Collect Project Information ### Description Gathers essential information about a Next.js project, including its package manager, Next.js version, and React version. ### Method N/A (Function call within the library) ### Endpoint N/A ### Parameters - **projectPath** (string) - Required - The absolute or relative path to the Next.js project. ### Request Example ```typescript import { collectInsights, type ProjectInsights } from 'next-lens/commands/info' const insights: ProjectInsights = await collectInsights('/path/to/nextjs-app') ``` ### Response #### Success Response - **ProjectInsights Object**: Contains project details. #### ProjectInsights Structure - **root** (string) - The absolute path to the project root. - **manifest** (PackageJson | null) - The parsed `package.json` content or null if not found. - **packageManager** (string | null) - The detected package manager (e.g., 'pnpm (lockfile)', 'npm (lockfile)'). - **nextVersion** (string | null) - The installed Next.js version. - **reactVersion** (string | null) - The installed React version. #### Response Example ```json { "root": "/absolute/path/to/project", "manifest": { "name": "my-next-app", "version": "1.0.0" }, "packageManager": "npm (lockfile)", "nextVersion": "15.0.2", "reactVersion": "18.3.1" } ``` ``` -------------------------------- ### POST /api/pages/error Source: https://context7.com/1weiho/next-lens/llms.txt Creates an `error.tsx` file for a specified page. This is used for handling and displaying errors gracefully. ```APIDOC ## POST /api/pages/error ### Description Creates an `error.tsx` file for a specified page to handle error states. ### Method POST ### Endpoint /api/pages/error ### Parameters #### Request Body - **file** (string) - Required - The path to the page file for which to create the error component (e.g., `app/dashboard/page.tsx`). ### Request Example ```json { "file": "app/dashboard/page.tsx" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **file** (string) - The path to the newly created error file (e.g., `app/dashboard/error.tsx`). #### Response Example ```json { "success": true, "file": "app/dashboard/error.tsx" } ``` ``` -------------------------------- ### Web Inspector API: POST /api/routes/methods Source: https://context7.com/1weiho/next-lens/llms.txt An HTTP POST endpoint for the Web Inspector API used to add a specific HTTP method to an existing API route. It requires the file path of the route and the method to be added in the request body. ```bash # Add HTTP method to existing route curl -X POST http://localhost:9453/api/routes/methods \ -H "Content-Type: application/json" \ -d '{ "file": "app/api/users/route.ts", "method": "POST" }' # Response: { "success": true } ``` -------------------------------- ### DELETE /api/routes Source: https://context7.com/1weiho/next-lens/llms.txt Deletes a specified route handler file from the project. ```APIDOC ## DELETE /api/routes ### Description Deletes a specified route handler file from the Next.js project. ### Method DELETE ### Endpoint /api/routes ### Parameters #### Request Body - **file** (string) - Required - The path to the route handler file to delete (e.g., `app/api/deprecated/route.ts`). ### Request Example ```json { "file": "app/api/deprecated/route.ts" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### DELETE /api/pages Source: https://context7.com/1weiho/next-lens/llms.txt Deletes a specified page file from the project. ```APIDOC ## DELETE /api/pages ### Description Deletes a specified page file from the Next.js project. ### Method DELETE ### Endpoint /api/pages ### Parameters #### Request Body - **file** (string) - Required - The path to the page file to delete (e.g., `app/old-page/page.tsx`). ### Request Example ```json { "file": "app/old-page/page.tsx" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### DELETE /api/routes/methods Source: https://context7.com/1weiho/next-lens/llms.txt Removes an HTTP method from an existing API route file. ```APIDOC ## DELETE /api/routes/methods ### Description Removes an HTTP method from an existing API route file. ### Method DELETE ### Endpoint `/api/routes/methods` (Web Inspector) ### Parameters #### Request Body - **file** (string) - Required - The relative path to the API route file. - **method** (string) - Required - The HTTP method to remove (e.g., 'POST', 'PATCH'). ### Request Example ```bash curl -X DELETE http://localhost:9453/api/routes/methods \ -H "Content-Type: application/json" \ -d '{ "file": "app/api/users/route.ts", "method": "POST" }' ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Transform Dynamic Route Segments to Path Format Source: https://context7.com/1weiho/next-lens/llms.txt Converts Next.js file-based routing segments into a path format suitable for route matching. It handles static segments, dynamic segments (like `[id]`), catch-all segments (`[...parts]`), and optional catch-all segments (`[[...optional]]`). ```typescript import { transformSegment } from 'next-lens/lib/utils' transformSegment('[id]') // → :id transformSegment('[slug]') // → :slug transformSegment('[...parts]') // → :parts* (catch-all) transformSegment('[[...optional]]') // → :optional*? (optional catch-all) transformSegment('static') // → static transformSegment('(group)') // → (group) - but filtered in routes ``` -------------------------------- ### DELETE /api/routes/methods Source: https://context7.com/1weiho/next-lens/llms.txt Removes an HTTP method from a route handler file. This is useful for consolidating or refactoring route definitions. ```APIDOC ## DELETE /api/routes/methods ### Description Removes an HTTP method from a route handler file. ### Method DELETE ### Endpoint /api/routes/methods ### Parameters #### Request Body - **file** (string) - Required - The path to the route handler file (e.g., `app/api/users/route.ts`). - **method** (string) - Required - The HTTP method to remove (e.g., `DELETE`, `POST`). ### Request Example ```json { "file": "app/api/users/route.ts", "method": "DELETE" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Web Inspector API: DELETE /api/routes/methods Source: https://context7.com/1weiho/next-lens/llms.txt An HTTP DELETE endpoint for the Web Inspector API designed to remove an HTTP method from an existing API route. The request body must specify the route's file path and the method to be removed. ```bash # Remove HTTP method from existing route curl -X DELETE http://localhost:9453/api/routes/methods \ -H "Content-Type: application/json" \ -d '{ "file": "app/api/users/route.ts", "method": "POST" }' # Response: { "success": true } ``` -------------------------------- ### Delete a Page File Source: https://context7.com/1weiho/next-lens/llms.txt Deletes a specified page file from the Next.js application. This is useful for cleaning up or removing old pages. The operation requires the file path of the page to be deleted. ```bash curl -X DELETE http://localhost:9453/api/pages \ -H "Content-Type: application/json" \ -d '{ "file": "app/old-page/page.tsx" }' ``` -------------------------------- ### Delete an API Route File Source: https://context7.com/1weiho/next-lens/llms.txt Deletes a specified API route file. This is useful for removing deprecated or unused API endpoints. The command requires the file path of the route to be deleted. ```bash curl -X DELETE http://localhost:9453/api/routes \ -H "Content-Type: application/json" \ -d '{ "file": "app/api/deprecated/route.ts" }' ``` -------------------------------- ### Filter Route Segments Excluding Groups and Slots Source: https://context7.com/1weiho/next-lens/llms.txt Demonstrates filtering Next.js route segments to exclude route groups (e.g., `(marketing)`) and parallel route slots (e.g., `@analytics`) when constructing the final route path. Only actual route segments are retained. ```typescript // Only actual route segments are included: const segments = ['app', '(marketing)', 'blog', '[slug]', 'page.tsx'] const filtered = segments.filter(shouldIncludeSegment) // → ['app', 'blog', '[slug]', 'page.tsx'] ``` -------------------------------- ### Remove HTTP Method from API Route Source: https://context7.com/1weiho/next-lens/llms.txt Removes a specific HTTP method from an API route file. This is useful for refactoring or deprecating endpoints. It requires the file path and the method to remove. ```bash curl -X DELETE http://localhost:9453/api/routes/methods \ -H "Content-Type: application/json" \ -d '{ "file": "app/api/users/route.ts", "method": "DELETE" }' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.