-
Notifications
You must be signed in to change notification settings - Fork 167
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
Project generated with typescript support cannot serve static file using fastify-static plugin #600
Comments
This is one of the major issues of typescript. You need to use some other tools to to copy those files. cc @fastify/typescript |
In my projects, I moved away from |
It doesn't matter if you are using
|
What I meant is that is metter of providing out of the box a way to copy static files from src to dist/build folders during the "compilation" process. Otherwise, we should add a paragraph that explains to put static files inside a folder outside the src. WDYT? |
I thought it is the fundamental knowledge of using
Yes and no. It is good to explain some special case in document, but just afraid if the same issue happened for others plugin. The document will be hard to read and understand. |
I did create a directory "public" at the root. I was getting the same issue of missing static files. Then I tried creating a static file inside the"src/routes" to see if it fixes the issue as I was unaware of the underlying cause. Documentation regarding the recommended way of serving static files when using typescript will be helpful. |
I think I'm having the same issue as I have a
it can't read from the |
In your dev/build scripts in package.json, adding a simple "cp -r src/public build/" solves the issue. |
Prerequisites
Fastify version
4.0.0
Plugin version
5.7.1
Node.js version
v19.3.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
manjaro
Description
I have generated a project with typescript support and installed
fastify-static
to servehello.html
file at the root url.I am getting this error
Route GET:/hello.html not found
on log when trying to access the root on browser.On browser I get
{"message":"Route GET:/hello.html not found","error":"Not Found","statusCode":404}
I have checked the
/dist
directory and it doesn't have thehello.html
file in it. I tried to delete thedist
directory and then restart the server usingnpm run dev
but it doesn't solve the issue.But when I tried to create a project without typescript it works as expected.
src
directorydist
directoryroot.ts
Project without typescript
Directory structure
root.js
Most likely I am making some mistake causing this issue but I want to be sure. Thanks.
Steps to Reproduce
Generate project
typescript support
without typescript
install fastify/static
npm i @fastify/static
Create
hello.html
file in/src/routes/
Make changes in
root.js
orroot.ts
in/src/routes/
Expected Behavior
I want to serve
hello.html
in the root URL.The text was updated successfully, but these errors were encountered: