a tool for shared writing and social publishing

fix uri redirect route

Changed files
+14 -6
app
lish
uri
[uri]
+14 -6
app/lish/uri/[uri]/route.ts
··· 9 */ 10 export async function GET( 11 request: NextRequest, 12 - { params }: { params: Promise<{ uri: string }> } 13 ) { 14 try { 15 const { uri: uriParam } = await params; ··· 32 const basePath = record.base_path; 33 34 if (!basePath) { 35 - return new NextResponse("Publication has no base_path", { status: 404 }); 36 } 37 38 // Redirect to the publication's hosted domain (temporary redirect since base_path can change) ··· 47 48 if (docInPub?.publication && docInPub.publications) { 49 // Document is in a publication - redirect to domain/rkey 50 - const record = docInPub.publications.record as PubLeafletPublication.Record; 51 const basePath = record.base_path; 52 53 if (!basePath) { 54 - return new NextResponse("Publication has no base_path", { status: 404 }); 55 } 56 57 // Ensure basePath ends without trailing slash ··· 60 : basePath; 61 62 // Redirect to the document on the publication's domain (temporary redirect since base_path can change) 63 - return NextResponse.redirect(`${cleanBasePath}/${uri.rkey}`, 307); 64 } 65 66 // If not in a publication, check if it's a standalone document ··· 74 // Standalone document - redirect to /p/did/rkey (temporary redirect) 75 return NextResponse.redirect( 76 new URL(`/p/${uri.host}/${uri.rkey}`, request.url), 77 - 307 78 ); 79 } 80
··· 9 */ 10 export async function GET( 11 request: NextRequest, 12 + { params }: { params: Promise<{ uri: string }> }, 13 ) { 14 try { 15 const { uri: uriParam } = await params; ··· 32 const basePath = record.base_path; 33 34 if (!basePath) { 35 + return new NextResponse("Publication has no base_path", { 36 + status: 404, 37 + }); 38 } 39 40 // Redirect to the publication's hosted domain (temporary redirect since base_path can change) ··· 49 50 if (docInPub?.publication && docInPub.publications) { 51 // Document is in a publication - redirect to domain/rkey 52 + const record = docInPub.publications 53 + .record as PubLeafletPublication.Record; 54 const basePath = record.base_path; 55 56 if (!basePath) { 57 + return new NextResponse("Publication has no base_path", { 58 + status: 404, 59 + }); 60 } 61 62 // Ensure basePath ends without trailing slash ··· 65 : basePath; 66 67 // Redirect to the document on the publication's domain (temporary redirect since base_path can change) 68 + return NextResponse.redirect( 69 + `https://${cleanBasePath}/${uri.rkey}`, 70 + 307, 71 + ); 72 } 73 74 // If not in a publication, check if it's a standalone document ··· 82 // Standalone document - redirect to /p/did/rkey (temporary redirect) 83 return NextResponse.redirect( 84 new URL(`/p/${uri.host}/${uri.rkey}`, request.url), 85 + 307, 86 ); 87 } 88