Here’s my usecase : I want to have a second public folder (alongside Strapi’s public/ own folder, which has its own public middleware
strapi::public). This folder would have this kind of structure :
... -- /src -- /public ⬅️ Strapi's own public folder -- /custom-public ⬅️ custom public folder -- /custom-public-subdirectory-1 ⬅️ public but protected - index.html - /styles - /scripts -- /custom-public-subdirectory-2 ⬅️ public but protected - index.html - /styles - /scripts -- /custom-public-subdirectory-3 ⬅️ public but protected - index.html - /styles - /scripts etc...
I tried to investigate by myself and found the definition for Strapi’s own public middleware, but I can"t seem to understand it.
I need to have a second public folder, with its own middleware because each subdirectories access will be protected with my own logic (those are paid content).
Strapi’s /public folder must still work.
My questions are :
- 1 : How can I write a middleware that make the subdirectories of this custom folder public ( accessible when hitting http://localhost:1337/custom-public/custom-public-subdirectory-x) and serving the index.html and the other resources (like styles and scripts).
- 2 : Add my own protection logic to that middleware, that gives you a 401 Forbidden, when trying to access it without having the rights to do so (i’m thinking adding something like a JWT in URL params for example http://localhost:1337/custom-public/custom-public-subdirectory-x?auth=jwt-token)