Skip to content
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

Static files not served with "wildcard: false" on windows #299

Closed
2 tasks done
ziimakc opened this issue May 14, 2022 · 3 comments
Closed
2 tasks done

Static files not served with "wildcard: false" on windows #299

ziimakc opened this issue May 14, 2022 · 3 comments

Comments

@ziimakc
Copy link
Contributor

ziimakc commented May 14, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

3.29.0

Plugin version

3.0.1

Node.js version

16.15.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

11

Description

I would like to disable wildcard to serve some files like favicon.ico for root requests GET /favicon.ico explicitly without glob.

Issue is that when wildcard: false files not served, while with wildcard: true they do.

import fastifyStatic from "@fastify/static";
import fp from "fastify-plugin";
import fastify from "fastify";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

function getDir(importMeta) {
  return dirname(fileURLToPath(importMeta.url));
}

const dir = getDir(import.meta);

const appFiles = async (app) => {
  await app.register(fastifyStatic, {
    root: join(dir, "./assets"),
    wildcard: false,
    decorateReply: true,
    list: true,
    prefix: "/",
    index: false,
  });
};

const appFilesPlugin = fp(appFiles, {
  name: "app-files",
});

const app = fastify({ logger: true, disableRequestLogging: false });
await app.register(appFilesPlugin);

app.get("/", {
  async handler() {
    return { ok: true };
  },
});

app
  .listen(3000, "0.0.0.0")
  .then(() => console.error("listening"))
  .catch((err) => console.error(err));

Steps to Reproduce

https://github.com/ZiiMakc/test

Expected Behavior

GET /favicon.ico should serve a file.

@ziimakc
Copy link
Contributor Author

ziimakc commented May 14, 2022

Oh, I see that it was fixed by PR

@ziimakc ziimakc closed this as completed May 14, 2022
@ziimakc
Copy link
Contributor Author

ziimakc commented May 15, 2022

Can we please release a new version to apply fix for v3 and v4?

@ziimakc ziimakc reopened this May 15, 2022
@ziimakc ziimakc changed the title Static files not served with "wildcard: false" Static files not served with "wildcard: false" on windows May 15, 2022
@mcollina
Copy link
Member

v6.1.0 is released with the above change. If you'd like to issue a PR to fix it also on v5 (branch v5.x), that would be great. Cherry-picking this commit might be enough.

@ziimakc ziimakc closed this as completed May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants