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?
Asked
Active
Viewed 252 times
1

ConductedClever
- 4,175
- 2
- 35
- 69
-
1There 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
-
1The 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 Answers
1
you can create a folder named public
, then under extendExpressApp
add the following code
app.use("/public", express.static("public"));
(follow express documentationhttps://expressjs.com/en/starter/static-files.html
)add this line under
ui
publicPages: ["public"],
to skip admin authentication
now your public folder should be accessible.

Dave Wong
- 315
- 2
- 10
-
I hoped it could be part of Keystonejs itself, but your solution also seems good although I haven't test it yet. – ConductedClever Feb 14 '23 at 05:40
-
Also note that I was serving those types of files with apache or nginx on the same port and reverse proxy other requests to Keystonejs. – ConductedClever Feb 14 '23 at 05:41
-
server by web server also works, if assets belong to the project, I like to put them in the same project folder – Dave Wong Apr 12 '23 at 03:37