From 6e9b668af91123162b9881df37ef421dd0a0416f Mon Sep 17 00:00:00 2001 From: "Luiz H. R. Silva" Date: Thu, 13 Jun 2024 11:34:00 -0300 Subject: [PATCH 1/2] 404 --- ferramentas/rodar_servidor.tsx | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ferramentas/rodar_servidor.tsx b/ferramentas/rodar_servidor.tsx index 4fb31de..230ff8f 100644 --- a/ferramentas/rodar_servidor.tsx +++ b/ferramentas/rodar_servidor.tsx @@ -118,7 +118,7 @@ gerar.then(() => { // 404 fastify.setNotFoundHandler((request, reply) => { const html404 = fs.readFileSync( - estaticos("node_modules").html["404.html"], + path.join(process.cwd(), estaticos("relativo").html["404.html"]), "utf8", ); diff --git a/package.json b/package.json index 2a7aefa..05266ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p-estaticos", - "version": "0.39.0", + "version": "0.40.0", "description": "", "main": "dist/index.js", "scripts": { From 3473a5b4ec6609dbc0fdf76e27cbb4cac302d2c0 Mon Sep 17 00:00:00 2001 From: "Luiz H. R. Silva" Date: Thu, 13 Jun 2024 12:12:04 -0300 Subject: [PATCH 2/2] melhoria de log --- ferramentas/rodar_servidor.tsx | 16 +++++++++++++++- package.json | 3 ++- pnpm-lock.yaml | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ferramentas/rodar_servidor.tsx b/ferramentas/rodar_servidor.tsx index 230ff8f..38959cb 100644 --- a/ferramentas/rodar_servidor.tsx +++ b/ferramentas/rodar_servidor.tsx @@ -10,6 +10,7 @@ import { gerar } from "./listar_arquivos"; import React, {} from "react"; import fastifyStatc from "@fastify/static"; +import dayjs from "dayjs"; import Fastify, {} from "fastify"; const { PORTA, PREFIXO } = ambiente; @@ -57,10 +58,23 @@ const criarHtml = (entrada: { gerar.then(() => { const fastify = Fastify({ - logger: true, + logger: false, + ignoreTrailingSlash: true, }); + fastify.addHook("onSend", async (request, reply) => { + console.log( + [ + dayjs().format("YYYY-MM-DD HH:mm:ss"), + request.method, + request.url, + reply.statusCode, + request.headers.site || request.headers.referer, + ].join(" "), + ); + }); + //cors fastify.register(cors, { origin: "*", diff --git a/package.json b/package.json index 05266ba..c6f889e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p-estaticos", - "version": "0.40.0", + "version": "0.41.0", "description": "", "main": "dist/index.js", "scripts": { @@ -21,6 +21,7 @@ "dependencies": { "@fastify/cors": "^9.0.1", "@fastify/static": "^7.0.4", + "dayjs": "^1.11.11", "fastify": "^4.27.0", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bb00da3..b7cc307 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@fastify/static': specifier: ^7.0.4 version: 7.0.4 + dayjs: + specifier: ^1.11.11 + version: 1.11.11 fastify: specifier: ^4.27.0 version: 4.27.0 @@ -248,6 +251,9 @@ packages: csstype@3.1.3: resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} + dayjs@1.11.11: + resolution: {integrity: sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==} + depd@2.0.0: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} @@ -831,6 +837,8 @@ snapshots: csstype@3.1.3: {} + dayjs@1.11.11: {} + depd@2.0.0: {} dotenv-cli@7.4.1: