From 1f88391c381383b3f494ba686aa93f675ad823b9 Mon Sep 17 00:00:00 2001 From: "Luiz H. R. Silva" Date: Thu, 13 Jun 2024 11:23:11 -0300 Subject: [PATCH] erro 404 --- ferramentas/rodar_servidor.tsx | 12 +++++++++++- package.json | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ferramentas/rodar_servidor.tsx b/ferramentas/rodar_servidor.tsx index 425582a..4fb31de 100644 --- a/ferramentas/rodar_servidor.tsx +++ b/ferramentas/rodar_servidor.tsx @@ -1,3 +1,4 @@ +import fs from "node:fs"; import path from "node:path"; import cors from "@fastify/cors"; import { renderToStaticMarkup } from "react-dom/server"; @@ -116,7 +117,16 @@ gerar.then(() => { // 404 fastify.setNotFoundHandler((request, reply) => { - reply.code(404).send(`Não encontrado: ${request.url}`); + const html404 = fs.readFileSync( + estaticos("node_modules").html["404.html"], + "utf8", + ); + + reply.header("content-type", "text/html; charset=utf-8"); + + reply + .code(404) + .send(html404.replace("{ERRO}", `Página não encontrada: ${request.url}`)); }); fastify.listen({ port: Number(PORTA) }, (err, address) => { diff --git a/package.json b/package.json index f98f569..2a7aefa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p-estaticos", - "version": "0.38.0", + "version": "0.39.0", "description": "", "main": "dist/index.js", "scripts": {