-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solved assets management with dyn route
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { createReadStream } from 'fs'; | ||
import {resolve,join} from 'path' | ||
import { config } from "@/config"; | ||
|
||
export async function GET({params}){ | ||
const imagePath = resolve(join(config.rootdir,config.content,params.path)); | ||
|
||
try { | ||
const stream = createReadStream(imagePath); | ||
|
||
// Identify the correct MIME type based on the file extension, or default to 'application/octet-stream' | ||
//const contentType = 'image/png' | ||
const contentType = 'image/svg+xml' | ||
|
||
return new Response(stream, { | ||
status: 200, | ||
headers: { | ||
'Content-Type': contentType, | ||
} | ||
}); | ||
} catch (error) { | ||
// Handle error, such as file not found | ||
return new Response('File not found', { status: 404 }); | ||
} | ||
} | ||
|
||
//TODO serve all assets - to check if in dev mode only | ||
export function getStaticPaths(){ | ||
if(import.meta.env.DEV){ | ||
const files = [ | ||
"panzoom/tree.svg" | ||
] | ||
return files.map((file)=>({params:{path:file}})) | ||
}else{ | ||
return [] | ||
} | ||
} |