DevDocs icon indicating copy to clipboard operation
DevDocs copied to clipboard

Frontend not displaying data

Open Maxinger15 opened this issue 1 year ago • 12 comments

Hi,

I have followed the install instructions in the readme for macos.

  • Cloned the repo
  • Changed the folder
  • run ./docker-start.sh

Now I have the problem, that when i insert a url on the frontend it says processing and i can see that some md and json files are created in the storage/markdown folder, but the frontend doesn`t update -> zero discovered pages, no extracted content, zero pages crawled, zero data extracted. If I reload the fronted it says waiting for url again.

System:

M4 Pro Macbook with MacOS 15.3.2 Docker via Orbstack Docker version 27.5.1, build 9f9e405

Container logs:

backend_log.txt crawlai_log.txt frontend_log.txt mcp_log.txt

Maxinger15 avatar Mar 19 '25 19:03 Maxinger15

Same for me, macOS via Docker Desktop.

osxdoc avatar Mar 23 '25 08:03 osxdoc

The markdown and json files are your files correct from the scraping or just example ones?

Secondly what do you see in docker logs for both front end and backend when you give it a URL and let it run?

Shubham-Khichi avatar Mar 27 '25 02:03 Shubham-Khichi

I had Roo Code's Debug Mode work on it, and here's the summary (written by Claude 3.7)


Task Completed

I've successfully resolved the ECONNREFUSED error in your Docker-based application:

Root Cause Analysis

The Next.js frontend was trying to connect to http://localhost:24125 instead of http://backend:24125 This happened because the environment variables in Dockerfile.frontend were set after the Next.js build process During build time, Next.js fell back to the default value in next.config.mjs, which was http://localhost:24125 In a Docker environment, localhost refers to the container itself, not other services Solution I modified Dockerfile.frontend to set the environment variables before the build step:

# Set environment variables first, so they're available during build
ENV PORT 3001
ENV BACKEND_URL http://backend:24125
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production

# Copy the rest of the application
COPY . .

# Create public directory if it doesn't exist
RUN mkdir -p public

# Next.js build (now with environment variables available)
RUN npm run build

This ensures that during the Next.js build process, process.env.BACKEND_URL is correctly set to http://backend:24125, allowing the frontend to properly communicate with the backend service within the Docker network.

Lessons Learned

Environment variables used during build time must be set before the build step in Dockerfiles In Docker environments, services should reference each other by service name, not localhost Next.js bakes environment variables into the build, so they need to be available at build time


Missing from this summary is also a change to app/api/storage/route.ts line 168, which is hardcoded to localhost instead of using process.env.BACKEND_URL

axmo avatar Mar 27 '25 03:03 axmo

@Shubham-Khichi I just pulled your latest commit with the fixes for the connection refused error on the frontend. The error is now gone, but the overall behaviour of my problem hasn´t changed. There is still nothing showing up in the frontend.

To your question about the stored markdown files: These are cleary new ones scraped from the url I have entered.

Here are my Docker Logs when I have entered https://tailwindcss.com/docs/styling-with-utility-classes as an url on the fronted and started processing.

backend_logs.txt

crawl4ai.txt

frontend_logs.txt

mcp_logs.txt

Maxinger15 avatar Mar 27 '25 19:03 Maxinger15

HI I am documenting this here for paper trail, so I can attach a PR to this issue.

Analysis of HeadersTimeoutError Issue

After examining the codebase, I've identified the root cause of the HeadersTimeoutError and can provide a robust solution.

Root Cause

The error HeadersTimeoutError with code UND_ERR_HEADERS_TIMEOUT is occurring in the Next.js API route (app/api/discover/route.ts) when it makes a fetch request to the backend API. This error occurs when the server takes too long to send the HTTP headers in response to a request.

The issue is in this specific part of the code:


// app/api/discover/route.ts
const response = await fetch(`${backendUrl}/api/discover`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ url, depth: validatedDepth }),
});

This fetch request doesn't have a timeout specified, so it's using the default timeout of the Undici HTTP client. When the backend takes too long to respond (which can happen when crawling complex websites), the request times out while waiting for headers.

Why This Is Happening

The backend API (backend/app/main.py) calls discover_pages in backend/app/crawler.py, which:

  • Makes a request to the Crawl4AI service with a 30-second timeout
  • Polls the Crawl4AI service up to 120 times with a 1-second interval between polls
  • Processes the response and generates markdown content

This entire process can take several minutes for complex websites, which exceeds the default timeout of the fetch request in the Next.js API route.

Implementation strategy.

Image

Shubham-Khichi avatar Mar 28 '25 16:03 Shubham-Khichi

Same for me, macOS via orbstack frontend log

Error in discover route: TypeError: fetch failed
    at async c (.next/server/app/api/discover/route.js:1:1183) {
  [cause]: [Error [HeadersTimeoutError]: Headers Timeout Error] {
    code: 'UND_ERR_HEADERS_TIMEOUT'
  }
}
Error name: TypeError
Error message: fetch failed
Error stack: TypeError: fetch failed
    at node:internal/deps/undici/undici:13502:13
    at async c (/app/.next/server/app/api/discover/route.js:1:1183)
    at async tr.do (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:18:17558)
    at async tr.handle (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:18:22188)
    at async doRender (/app/node_modules/next/dist/server/base-server.js:1452:42)
    at async responseGenerator (/app/node_modules/next/dist/server/base-server.js:1822:28)
    at async NextNodeServer.renderToResponseWithComponentsImpl (/app/node_modules/next/dist/server/base-server.js:1832:28)
    at async NextNodeServer.renderPageComponent (/app/node_modules/next/dist/server/base-server.js:2259:24)
    at async NextNodeServer.renderToResponseImpl (/app/node_modules/next/dist/server/base-server.js:2297:32)
    at async NextNodeServer.pipeImpl (/app/node_modules/next/dist/server/base-server.js:959:25)
Network error detected - possible connection issue to backend service
TypeError detected - possible issue with response format or undefined values

gonisan avatar Apr 09 '25 17:04 gonisan

+1

docker logs -f devdocs-mcp
ERROR: Error reading metadata for c18eaa70-b590-42ea-8c53-c7545d740fa9: Extra data: line 15 column 2 (char 414)
ERROR: Error reading metadata for c18eaa70-b590-42ea-8c53-c7545d740fa9: Extra data: line 15 column 2 (char 414)
ERROR: Error reading metadata for c18eaa70-b590-42ea-8c53-c7545d740fa9: Extra data: line 15 column 2 (char 414)
ERROR: Error reading metadata for c18eaa70-b590-42ea-8c53-c7545d740fa9: Extra data: line 15 column 2 (char 414)
ERROR: Error reading metadata for c18eaa70-b590-42ea-8c53-c7545d740fa9: Extra data: line 15 column 2 (char 414)
ERROR: Error reading metadata for 80711765-2df4-4c77-bc62-7e28ca637188: Extra data: line 15 column 3 (char 415)
ERROR: Error reading metadata for 80711765-2df4-4c77-bc62-7e28ca637188: Extra data: line 15 column 3 (char 415)
ERROR: Error reading metadata for 80711765-2df4-4c77-bc62-7e28ca637188: Extra data: line 15 column 3 (char 415)
ERROR: Error reading metadata for 80711765-2df4-4c77-bc62-7e28ca637188: Extra data: line 15 column 3 (char 415)
ERROR: Error reading metadata for 80711765-2df4-4c77-bc62-7e28ca637188: Extra data: line 15 column 3 (char 415)

sewall2025 avatar Apr 10 '25 05:04 sewall2025

Triaging this, standby

Shubham-Khichi avatar Apr 10 '25 05:04 Shubham-Khichi

update to new release still error

docker logs -f devdocs-mcp
ERROR: Error reading metadata for ca71c641-8f5e-4b84-a8ab-8492cac4b6d9: Extra data: line 15 column 2 (char 414)
ERROR: Error reading metadata for 6ef94063-563a-4e5f-95ae-90f3627e2364: Expecting value: line 1 column 1 (char 0)

edisonzf2020 avatar Apr 11 '25 14:04 edisonzf2020

Hi @edisonzf2020 this is an MCP issue, please run the script /script/mcp/check_mcp_health.sh after you ran ./docker-start.sh, if issue still persists please create another issue for this.

Shubham-Khichi avatar Apr 11 '25 14:04 Shubham-Khichi

I have a different experience. The front end never updates with the new crawl results. Its always just the default "ag2" docs. I see in the browser debugger that the API call to get the files only ever returns 1 file. Something in the backend that finds the new results is not working

ftballguy45 avatar May 05 '25 19:05 ftballguy45

Hi @ftballguy45 can you share screenshot of the UI? Have you been using the latest branch called Feature-Main

Shubham-Khichi avatar May 05 '25 20:05 Shubham-Khichi