erro 404
This commit is contained in:
parent
10d1e0dd4d
commit
1f88391c38
2 changed files with 12 additions and 2 deletions
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue