Skip to content

Commit f6a8943

Browse files
bug: fixed writing and reading data for nextjs
1 parent 3988a44 commit f6a8943

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/cacheHandler/strategy/s3.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ export class S3Cache implements CacheStrategy {
4141
)
4242
}
4343

44-
async get(pageKey: string, cacheKey: string, ctx: CacheContext): Promise<CacheEntry | null> {
44+
async get(pageKey: string, cacheKey: string): Promise<CacheEntry | null> {
4545
if (!this.client) return null
4646

4747
const pageData = await this.client
4848
.getObject({
4949
Bucket: this.bucketName,
50-
Key: `${pageKey}/${cacheKey}.${ctx.isAppRouter ? CacheExtension.RSC : CacheExtension.JSON}`
50+
Key: `${pageKey}/${cacheKey}.${CacheExtension.JSON}`
5151
})
5252
.catch((error) => {
5353
if (NOT_FOUND_ERROR.includes(error.name)) return null
@@ -58,7 +58,7 @@ export class S3Cache implements CacheStrategy {
5858

5959
const response = await pageData.Body.transformToString('utf-8')
6060

61-
return ctx.isAppRouter ? response : JSON.parse(response)
61+
return JSON.parse(response)
6262
}
6363

6464
async set(pageKey: string, cacheKey: string, data: CacheEntry, ctx: CacheContext): Promise<void> {
@@ -82,6 +82,14 @@ export class S3Cache implements CacheStrategy {
8282
ContentType: 'text/html'
8383
})
8484
)
85+
promises.push(
86+
this.client.putObject({
87+
...input,
88+
Key: `${input.Key}.${CacheExtension.JSON}`,
89+
Body: JSON.stringify(data),
90+
ContentType: 'application/json'
91+
})
92+
)
8593
if (ctx.isAppRouter) {
8694
promises.push(
8795
this.client.putObject({
@@ -91,15 +99,6 @@ export class S3Cache implements CacheStrategy {
9199
ContentType: 'text/x-component'
92100
})
93101
)
94-
} else {
95-
promises.push(
96-
this.client.putObject({
97-
...input,
98-
Key: `${input.Key}.${CacheExtension.JSON}`,
99-
Body: JSON.stringify(data.value.pageData),
100-
ContentType: 'application/json'
101-
})
102-
)
103102
}
104103
} else {
105104
promises.push(

src/lambdas/edgeRouting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const handler = async (
9797

9898
if (isFileExists) {
9999
// Modify s3 path request
100-
request.uri = `/${s3Key}${queryParams}`
100+
request.uri = `/${s3Key}`
101101

102102
// If file exists, allow the request to proceed to S3
103103
callback(null, request)

0 commit comments

Comments
 (0)