sitemap-module
sitemap-module copied to clipboard
feat: Support option to access req.headers.host in dynamic routes function
This PR allows you to access req.headers.host when dynamically generating routes as requested in #217 #216 #215 #11
✨ Helpful for multi-tenant projects where the subdomain is needed to identify a user [user].maindomain.com
In order to use it the dynamicHost option must be enabled. Then the host parameter is available to be used in the routes function.
See example:
sitemap: {
dynamicHost: true,
routes: async (host) => {
const subdomain = host.split('.')[0]
const res = axios.get('https://myapi.com/getAllPages?user=' + subdomain)
return res.data
}
}
––––––––––––-
This is my first PR ever on Github and the solution is quite hacky – so please take it with a grain of salt and see it more as an inspiration on how this functionality could be achieved.
I'd like this aswell, I've used your "hacky" solution, works perfect.
Do you mind taking a look at it @NicoPennec ?
Hi @rylax & @Atinux, I just came back from holidays.
Using the hostname as the cache ID sounds like a smart idea. I will be looking in depth this week. Thanks @rylax for this proposal.
@rylax
in your commit it is necessary to restore the 25th line }, in order to close async load(key, callback) { in lib/cache.js. The rest is ok and everything works.
@rylax
in your commit it is necessary to restore the 25th line
},in order to closeasync load(key, callback) {inlib/cache.js. The rest is ok and everything works.
Thanks for pointing it out. Corrected it now. One can see that this is my first PR as the commit doesn't seem to go through the checks either 😬
@NicoPennec could you check this PR please?
Is this going to get picked up someday?
we need this feature