Served static HTML file fails to load resources
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- css, javascript, node.js, typescript
Direzione di ricerca
Riproduci il progetto generato da fastify-cli v7.0.1 con lo script dev ed esamina dist/routes/root.js, dist/public/index.html e la directory dist/assets. Inizia dalla registrazione di fastifyStatic e dalla route root, quindi verifica come l’app generata espone i file pubblici. Il lavoro è completato quando le risorse CSS e JavaScript collegate vengono caricate senza risposte 404 nel progetto generato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
Ok - I'm at the end of my rope on this one and I need a little help!
In short, the problem is. I'm serving a static html file with links to external javascript files and css files and these files are not being found. It seems like the Fastify router is trying to route the links (if that makes sense).
Here are the details:
I have created a new Fastify project using fastify-cli v7.0.1 with: fastify generate my-project --esm --lang=ts
Using the npm scripts from the generated project, I run "dev" and the html file is served ok, but I get a 404 on GET http://localhost:8000/assets/mdr.css (the css file linked to the html file).
The error on route "/":
{
"message": "Route GET:/assets/mdr.css not found",
"error": "Not Found",
"statusCode": 404
}
Here is the index.html file:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="./favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Home Page</title>
<link rel="stylesheet" href="assets/mdr.css"> <!-- CANNOT FIND THIS FILE -->
<!-- I ommitted the JS script as this is producing the same error and need to simplfy -->
</head>
<body
<div>Serving HTML from dist/public REV 1</div>
</body>
</html>
Here is my /dist folder structure:
/dist
app.js
/assets
mdr.css
/plugins
sensible.js <-- generated
support.js <-- generated
/public
index.html
/routes
/example
index.js <-- generated
root.js
And my root.js route:
import { FastifyPluginAsync } from "fastify";
import path from "path";
import { fileURLToPath } from "url";
import fastifyStatic from "@fastify/static";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const root: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
fastify.register(fastifyStatic, {
root: path.join(__dirname, "../","public"),
prefix: "/assets/", //<-- secondary problem - if set to "/public" I get an error that it is already defined somewhere else (not by me)
});
fastify.get("/", async function (request, reply:any) {
return reply.sendFile("index.html");
});
};
export default root;
The generated app is using Autoload on routes and plugins, all created by the generator.
I have just about everything I can think of to fix this and have not been able to.
Any help would be appreciated!
Thanks
_mark
- Lingua principale
- JavaScript
- Stelle
- 733
- Fork
- 179
- Merge medio
- 8g 12h
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fastify/fastify-cli
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
fastify/fastify-cli#846 · 2 commenti ·
-
Options propagationAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
fastify/fastify-cli#841 ·
-
Generated Fastify ESM/TS app has broken `npm test` command (FASTIFY_AUTOLOAD_TYPESCRIPT)Forse già presa @GhaythBenAbid l’ha presa 25 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
fastify/fastify-cli#835 · 2 commenti ·
-
Adding Path Alias Support in fastify-cliForse di nuovo libera @ali139713 l’ha presa 48 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
fastify/fastify-cli#806 · 1 commento · 7 reazioni ·
-
Only watch specified directory (--watch CLI param)Forse già presa @josephreilly22 l’ha presa 237 giorni fa. Apertagood first issue
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
fastify/fastify-cli#787 · 5 commenti · 2 reazioni ·
Tutte le issue di fastify/fastify-cli
Issue simili
-
Progress difficulty filter lists Hard before MediumForse già presa @Pandamachi l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
sysprog21/codetrial#281 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[dsh-plugin.org | dsh-plugin-hub] plugin distribution incomplete: yjh051108/dsh-routing-suiteAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 71/100
yjh051108/dsh-routing-suite#227 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
needs-triage release-watch
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
remoteintech/remote-jobs#2271 ·
I maintainer di solito rispondono entro 1 giorno