-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wildcard glob support #178
Comments
The problem with the If somebody would like to work on this problem, adding another option in to specify the glob pattern would be good: it should work with |
I thought that was a feature, not a bug :P To clarify, I'm not saying it needs to be added back if there is a different way to do it. It appears the E.g.
Could you confirm if the two lines are effectively the same? In testing, it appears to work as expected, but didn't want to get hit with a gotcha later because I misunderstood something. On a side note, Appreciate the help :) |
Calling it |
Well it was but we got a few issue reports that "it failed to detect new files" and it was really confusing for a few users. So, we removed it. It seems it's easy to add it back via |
I was the one who originally added the I have now upgraded to 4.x and use something like this: const prefix = '/public';
const assetRoot = path.join(process.cwd(), '/assets');
app.register(fastifyStatic, { root: assetRoot, wildcard: true, decorateReply: true });
const assetPaths = glob.sync(path.join(assetRoot, '/**/*.{css,js}'));
const assets = assetPaths.map((path) => {
return {
diskPath: path.replace(assetRoot, ''),
routePath: path.replace(assetRoot, prefix),
};
});
for (const asset of assets) {
app.get(asset.routePath, (_request, reply) => {
reply.sendFile(asset.diskPath, assetRoot);
});
} I think this should work similar to before, but maybe one of the maintainers can confirm. I was considering using |
Would it be okay to add something like globOverride for people who want make own behavior? |
Calling it |
Wouldn't it be better to allow to pass additional(all) options to glob too?! |
That would also be ok |
Need help: #375 (comment) |
It looks like passing a glob to wildcard was a breaking change in the 4.x release (#175), but it's unclear why it was removed. It's an extremely valuable feature and something I've used across multiple applications. Is it possible to revert that change and keep the functionality, or is there a workaround to keep similar behavior without having to rework directory structures?
For one of the use cases specifically, by using globs, it's possible to keep static assets next to the relevant code they're used with rather than having to maintain a separate assets directory. It's in a similar vein of keeping your tests next to the code versus having a separate tests directory, etc.
It'd be awesome to keep this functionality if there wasn't a strong reason to remove it.
EDIT: I did see that #172 was added, but wasn't sure if that would actually allow the same behavior or if there were differences.
The text was updated successfully, but these errors were encountered: