tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
292
fork
atom
a tool for shared writing and social publishing
292
fork
atom
overview
issues
27
pulls
pipelines
fix uri redirect route
awarm.space
3 months ago
665be134
cd084380
+14
-6
1 changed file
expand all
collapse all
unified
split
app
lish
uri
[uri]
route.ts
+14
-6
app/lish/uri/[uri]/route.ts
···
9
9
*/
10
10
export async function GET(
11
11
request: NextRequest,
12
12
-
{ params }: { params: Promise<{ uri: string }> }
12
12
+
{ params }: { params: Promise<{ uri: string }> },
13
13
) {
14
14
try {
15
15
const { uri: uriParam } = await params;
···
32
32
const basePath = record.base_path;
33
33
34
34
if (!basePath) {
35
35
-
return new NextResponse("Publication has no base_path", { status: 404 });
35
35
+
return new NextResponse("Publication has no base_path", {
36
36
+
status: 404,
37
37
+
});
36
38
}
37
39
38
40
// Redirect to the publication's hosted domain (temporary redirect since base_path can change)
···
47
49
48
50
if (docInPub?.publication && docInPub.publications) {
49
51
// Document is in a publication - redirect to domain/rkey
50
50
-
const record = docInPub.publications.record as PubLeafletPublication.Record;
52
52
+
const record = docInPub.publications
53
53
+
.record as PubLeafletPublication.Record;
51
54
const basePath = record.base_path;
52
55
53
56
if (!basePath) {
54
54
-
return new NextResponse("Publication has no base_path", { status: 404 });
57
57
+
return new NextResponse("Publication has no base_path", {
58
58
+
status: 404,
59
59
+
});
55
60
}
56
61
57
62
// Ensure basePath ends without trailing slash
···
60
65
: basePath;
61
66
62
67
// Redirect to the document on the publication's domain (temporary redirect since base_path can change)
63
63
-
return NextResponse.redirect(`${cleanBasePath}/${uri.rkey}`, 307);
68
68
+
return NextResponse.redirect(
69
69
+
`https://${cleanBasePath}/${uri.rkey}`,
70
70
+
307,
71
71
+
);
64
72
}
65
73
66
74
// If not in a publication, check if it's a standalone document
···
74
82
// Standalone document - redirect to /p/did/rkey (temporary redirect)
75
83
return NextResponse.redirect(
76
84
new URL(`/p/${uri.host}/${uri.rkey}`, request.url),
77
77
-
307
85
85
+
307,
78
86
);
79
87
}
80
88