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 path from "node:path";
|
||||||
import cors from "@fastify/cors";
|
import cors from "@fastify/cors";
|
||||||
import { renderToStaticMarkup } from "react-dom/server";
|
import { renderToStaticMarkup } from "react-dom/server";
|
||||||
|
|
@ -116,7 +117,16 @@ gerar.then(() => {
|
||||||
|
|
||||||
// 404
|
// 404
|
||||||
fastify.setNotFoundHandler((request, reply) => {
|
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) => {
|
fastify.listen({ port: Number(PORTA) }, (err, address) => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "p-estaticos",
|
"name": "p-estaticos",
|
||||||
"version": "0.38.0",
|
"version": "0.39.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue