fastify / fastify-vite

Fastify plugin for Vite integration.
MIT License
861 stars 72 forks source link

Files in /public folder are not served in production mode #105

Closed ranyefet closed 6 months ago

ranyefet commented 1 year ago

Prerequisites

Fastify version

4.13.0

Plugin version

3.0.8

Node.js version

16.15.1

Operating system

macOS

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

latest

Description

Hello,

In my Vite application I'm using the public folder feature to serve static files without transformations such as favicon.svg and other js/css files.

After building for production and running my fastify app I noticed that the these files are not served.

It appears that fastify-vite is only serving index.html and everything in the assets folder.

build
  assets/
    index.[hash].js
  favicon.svg - NOT SERVED
  script1.js - NOT SERVED
  index.html

I would expect that it will support public folder feature and serve everything in the build folder as is.

Steps to Reproduce

  1. Add public folder under your client folder
  2. Put some file inside, for example robots.txt
  3. Run build command
  4. Run app in production mode and access localhost/robots.txt

Expected Behavior

Fastify Vite should serve all files in build folder as static files and not just index.html and assets folder.

tantaman commented 1 year ago

workaround for you:

import fastifyStatic from "@fastify/static";

await server.register(fastifyStatic, {
  root: new URL("./public", import.meta.url),
});
ranyefet commented 1 year ago

@tantaman Thanks I already have a workaround but I still think it should be solved in fastidy-vite

galvez commented 9 months ago

You're right! This should be handled by @fastify/vite — I'm adding it in the next minor.

galvez commented 6 months ago

Fixed in v6.0.1.