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.

Set baseUrl for Payload UI

default discord avatar
nettirklast year
5

I want to deploy payload under

/foo

instead on the root.


How can I set the baseUrl to

/foo

?


Currently payload redirects to

/admin

instead of

/foo/admin

and also tries to load static files from

/admin/assets/...

instead of

/foo/admin/assets/...
  • discord user avatar
    denolfe
    last year

    You can adjust the routes in the config. Here are the defaults

    https://github.com/payloadcms/payload/blob/main/packages/payload/src/config/defaults.ts#L48
  • default discord avatar
    nettirklast year
    @967118574445547650

    Thank you for your answer.


    After adjusting the routes config, the path in the built index.html (I assume thats the admin UI?) is changed to my desired prefix.


    But before I reach the admin UI, payload still tries to redirect to

    /admin

    instead of

    prefix/admin

    .


    I couldn't find any setting to change this behaviour



    This is the call stack in the inspector:


    It first redirects to add the missing trailing slash and than it redirects to /admin instead of /cos-cms/admin



    (Yes I'm currently hosting payload on our internal gitlab, it's only temporary 😉 But that's why I need to change the base path to

    cos-cms

    in my case)



    Thats my payload.config.ts


    I've set the variables to

    cos-cms
  • default discord avatar
    augdustlast year

    Think there's a redirect to /admin happening in the server.ts file by default, worth checking out :)

  • discord user avatar
    denolfe
    last year

    Yes, depending on the template you've used, there may be a redirect to /admin. This was added to assist newcomers in accessing the admin panel. Removing this may resolve your issue.

    https://github.com/payloadcms/payload/blob/main/templates/website/src/server.default.ts#L20-L23
  • default discord avatar
    nettirklast year
    @170674545965924352

    @967118574445547650

    Thank you both!


    I removed the redirection in server.default.ts and know it works (aside from the redirection ;))

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.