server.use(
"/assets/*",
serveStatic({
root: "./build/client/assets",
getContent: async (filePath) => {
const resolvedPath = path.join(
process.cwd(),
"./build/client/assets",
filePath
)
try {
const data = await fs.readFile(resolvedPath)
const response = new Response(data)
// Set long-term caching: 1 year (31536000 seconds), immutable
response.headers.set(
"Cache-Control",
"public, max-age=31536000, immutable"
)
return response
} catch {
return null // If file not found, proceed to next middleware
}
},
})
)
// Serve static files from 'build/client' for all other paths
server.use(
"/*",
serveStatic({
root: "./build/client",
getContent: async (filePath, c) => {
const resolvedPath = path.join(
process.cwd(),
"./build/client",
filePath
)
try {
const data = await fs.readFile(resolvedPath)
const response = new Response(data)
// Set short-term caching: 1 hour (3600 seconds)
response.headers.set("Cache-Control", "public, max-age=3600")
return response
} catch {
return null // If file not found, proceed to next middleware
}
},
})
)
server.use(
"/assets/*",
serveStatic({
root: "./build/client/assets",
getContent: async (filePath) => {
const resolvedPath = path.join(
process.cwd(),
"./build/client/assets",
filePath
)
try {
const data = await fs.readFile(resolvedPath)
const response = new Response(data)
// Set long-term caching: 1 year (31536000 seconds), immutable
response.headers.set(
"Cache-Control",
"public, max-age=31536000, immutable"
)
return response
} catch {
return null // If file not found, proceed to next middleware
}
},
})
)
// Serve static files from 'build/client' for all other paths
server.use(
"/*",
serveStatic({
root: "./build/client",
getContent: async (filePath, c) => {
const resolvedPath = path.join(
process.cwd(),
"./build/client",
filePath
)
try {
const data = await fs.readFile(resolvedPath)
const response = new Response(data)
// Set short-term caching: 1 hour (3600 seconds)
response.headers.set("Cache-Control", "public, max-age=3600")
return response
} catch {
return null // If file not found, proceed to next middleware
}
},
})
)