Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

`url` field shows absolute URL in local, but relative URL in prod

default discord avatar
gabe.algo2 years ago
4

When uploading files to a

Media

collection, the

url

displays as the absolute URL in local dev, but only shows the relative path in prod (deployed to Payload Cloud).



For example, when querying a

User

that has an

avatar

field with relationship to

Media

:



Local:


{
"id": "645d8e5115c5b421de227a98",
...
"avatar": {
  "id": "645e035d6435660db51755de",
   ...
  "url": "http://localhost:4000/media/avatar.jpg"
 },
}


Prod:


{
"id": "645d8e5115c5b421de227a98",
...
"avatar": {
  "id": "645e035d6435660db51755de",
   ...
  "url": "/media/avatar.jpg"
 },
}


Is this intended or is it a bug?

  • discord user avatar
    dribbens
    2 years ago

    Are both running the same version of Payload? There was a recent small feature added in the latest version that could have introduced a bug. 1f 1.7.5 works but 1.8.2 doesn't, I would point to it being a new bug.



    What does your upload collection config look like? Are you using an env var for staticURL that could be different between environments?

  • default discord avatar
    gabe.algo2 years ago

    My collection config looks like this:



    import type { CollectionConfig, Field } from 'payload/types'
    
    const alt: Field = {
      name: 'alt',
      label: 'Alt Text',
      type: 'text',
      required: true
    }
    
    export const Media: CollectionConfig = {
      slug: 'media',
      access: {
        read: (): boolean => true // Everyone can read Media
      },
      upload: {
        staticURL: '/media',
        staticDir: 'media',
        mimeTypes: ['image/*', 'video/*'],
        adminThumbnail: 'card',
        imageSizes: [
          {
            name: 'card',
            width: 640,
            height: 480
          },
          {
            name: 'feature',
            width: 1024,
            height: 576
          }
        ]
      },
      fields: [alt]
    }
    
    export default Media


    Using version Payload 1.8.2



    not using any env vars outside of what Payload Cloud configures (I also just installed the Payload Cloud plugin to see if that would fix it, but no luck)

  • default discord avatar
    martafiixek2 years ago

    I think the difference may be ENV vars



    Does your config contain serverURL property?



  • default discord avatar
    gabe.algo2 years ago

    my config does have

    serverURL

    specified. Do I need to add the

    PAYLOAD_PUBLIC_SERVER_URL

    env var to the cloud config as well? I'd assumed Payload automatically sets that.



    oh that was it - I had to set

    PAYLOAD_PUBLIC_SERVER_URL

    in Payload Could. Thank you!!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.