1

I am using Keystonejs 6 and some models contain image type fields. When fetching this data I get a src of that image which points to /public/images/myimage.png. This link successfully gets loaded with admin panel logged in (session created) but when I request this src address from a browser anonymously, it redirects my request to the signin page. I can't find setup guide about static serving in Keystone 6. Although in Keystone 5 it seems exist in the documentation, in Keystone 6 nothing I can find in documents or community forum. Does Keystone 6 supports anonymous static file serving (serving public directory) and if it is possible how can I do this?

ConductedClever
  • 4,175
  • 2
  • 35
  • 69
  • 1
    There isn't really a good answer to this yet. Keystone 6 is still prerelease and the image functionality is incomplete. – Molomby Sep 15 '21 at 06:48
  • 1
    The intention is that images (and files) will be available publicly if you have the (securely random) ID associated with them. This lets you limit access to them (using the KS access control functionality) but still use them in your public site, newsletters, etc. if needed. This'll be the case whether the app is using the local storage or a cloud backend. I'll post and answer here once the functionality is released properly. – Molomby Sep 15 '21 at 06:54

1 Answers1

1

you can create a folder named public, then under extendExpressApp add the following code

  1. app.use("/public", express.static("public")); (follow express documentation https://expressjs.com/en/starter/static-files.html)

  2. add this line under ui publicPages: ["public"], to skip admin authentication

now your public folder should be accessible.

enter image description here

Dave Wong
  • 315
  • 2
  • 10