Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error of the "auth_doc" with "url_prefix" #366

Open
tark1998 opened this issue Dec 19, 2024 · 2 comments · May be fixed by #367
Open

Error of the "auth_doc" with "url_prefix" #366

tark1998 opened this issue Dec 19, 2024 · 2 comments · May be fixed by #367

Comments

@tark1998
Copy link

tark1998 commented Dec 19, 2024

Hi, I tried run y-sweet server in local with folloing docker-compose.yml

ysweet:
    image: y-sweet
    container_name: ysweet
    network_mode: host
    volumes:
      - /..../data:/data
    ports:
      - "8092:8092"
    command: y-sweet serve /data --url-prefix=http://0.0.0.0:8092 --port 8092 --host 0.0.0.0

but when i tried getDocAsUpdate in my Next.js /doc/_docId_/route.ts:

import { DocumentManager } from '@y-sweet/sdk';
import { NextResponse } from 'next/server'
import * as Y from 'yjs'

// Define the interface for URL parameters
interface Params {
  docId: string;
}

const manager = new DocumentManager("ys://0.0.0.0:8092");

export async function GET(request: Request, 
	{ params }: { params: Params } // Type the context with Params
) {
  try {
    // Extract query parameters from the URL
    const { docId } = params; // Extract params

    let update = await manager.getDocAsUpdate(docId || "")
    return NextResponse.json(update)
    /*
    doc.transact(() => {
      Y.applyUpdate(doc, update)
    })
    */

  } catch (error) {
    console.error('Error processing request:', error);
  }
}

I got the error message:

nextjs      | Error processing request: e [YSweetError]: ServerError: Server responded with 404 Not Found. URL: http://0.0.0.0:8092//d/a7b6b050-995d-4204-a5d0-51fe6582d62e/as-update?z=s0hd13w9i1
nextjs      |     at o.request (/app/.next/server/chunks/91.js:12:16934)
nextjs      |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
nextjs      |     at async n.getAsUpdate (/app/.next/server/chunks/91.js:12:17153)
nextjs      |     at async s.getDocAsUpdate (/app/.next/server/chunks/91.js:12:18383)
nextjs      |     at async c (/app/.next/server/app/relay/[relayId]/doc/[docId]/as-update/route.js:1:633)
nextjs      |     at async /app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:34666
nextjs      |     at async eS.execute (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:25813)
nextjs      |     at async eS.handle (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:35920)
nextjs      |     at async doRender (/app/node_modules/next/dist/server/base-server.js:1377:42)
nextjs      |     at async cacheEntry.responseCache.get.routeKind (/app/node_modules/next/dist/server/base-server.js:1599:28) {
nextjs      |   cause: {
nextjs      |     code: 'ServerError',
nextjs      |     status: 404,
nextjs      |     message: 'Not Found',
nextjs      |     url: 'http://0.0.0.0:8092//d/a7b6b050-995d-4204-a5d0-51fe6582d62e/as-update?z=s0hd13w9i1'
nextjs      |   }
nextjs      | }

I found that the url http://0.0.0.0:8092//d/a7b6b... looks wired, so i edit the craftes/y-sweet/src/server.rs as

async fn auth_doc(
   ....
    let base_url = if let Some(url_prefix) = &server_state.url_prefix {
        // format!("{url_prefix}/d/{doc_id}")
        // I CHANGE TO
        format!("{url_prefix}d/{doc_id}")
    } else {
        format!("http://{host}/d/{doc_id}")
    };
   ....

then it works!

What am I missing? Thanks!

@paulgb paulgb linked a pull request Dec 19, 2024 that will close this issue
@paulgb
Copy link
Member

paulgb commented Dec 19, 2024

Thanks for reporting. You're not missing anything, that's a bug! I've opened #367 with a fix. Sorry about that!

@tark1998
Copy link
Author

Thanks for the quick response and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants