File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
apps/climatemappedafrica/src/payload Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 1+ import transformDocMediaUrl from "../utils/transformDocMediaUrl" ;
2+
13const Media = {
24 slug : "media" ,
35 admin : {
@@ -22,7 +24,7 @@ const Media = {
2224 } ,
2325 ] ,
2426 hooks : {
25- afterRead : [ ( { doc } ) => ( { ... doc , src : doc . url } ) ] ,
27+ afterRead : [ ( { doc } ) => transformDocMediaUrl ( doc ) ] ,
2628 } ,
2729} ;
2830
Original file line number Diff line number Diff line change 1+ const transformDocMediaUrl = ( doc ) => {
2+ // Can't use absolute URLs in src because we set PAYLOAD_PUBLIC_APP_URL to localhost at build-time & will lead to 404 at runtime
3+ // Solution: use relative URLs
4+ const { pathname } = new URL ( doc . url ) ;
5+ return {
6+ ...doc ,
7+ alt : doc . alt ?? null ,
8+ src : pathname ,
9+ url : pathname ,
10+ } ;
11+ } ;
12+
13+ export default transformDocMediaUrl ;
You can’t perform that action at this time.
0 commit comments