import cors from "@fastify/cors";

This commit is contained in:
Luiz H. R. Silva 2024-06-12 19:40:48 -03:00
parent fa975b9743
commit 10d1e0dd4d
3 changed files with 33 additions and 2 deletions

View file

@ -1,4 +1,5 @@
import path from "node:path"; import path from "node:path";
import cors from "@fastify/cors";
import { renderToStaticMarkup } from "react-dom/server"; import { renderToStaticMarkup } from "react-dom/server";
import { estaticos } from "../src"; import { estaticos } from "../src";
import { ambiente } from "./ambiente"; import { ambiente } from "./ambiente";
@ -56,10 +57,14 @@ const criarHtml = (entrada: {
gerar.then(() => { gerar.then(() => {
const fastify = Fastify({ const fastify = Fastify({
logger: true, logger: true,
ignoreTrailingSlash: true, ignoreTrailingSlash: true,
}); });
//cors
fastify.register(cors, {
origin: "*",
});
fastify.route({ fastify.route({
method: "GET", method: "GET",
url: "/", url: "/",
@ -116,6 +121,8 @@ gerar.then(() => {
fastify.listen({ port: Number(PORTA) }, (err, address) => { fastify.listen({ port: Number(PORTA) }, (err, address) => {
if (err) throw err; if (err) throw err;
console.log(`${new Date().toISOString()} Servidor ${PREFIXO} Rodando em ${address}`); console.log(
`${new Date().toISOString()} Servidor ${PREFIXO} Rodando em ${address}`,
);
}); });
}); });

View file

@ -19,6 +19,7 @@
}, },
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@fastify/cors": "^9.0.1",
"@fastify/static": "^7.0.4", "@fastify/static": "^7.0.4",
"fastify": "^4.27.0", "fastify": "^4.27.0",
"react": "^18.3.1", "react": "^18.3.1",

23
pnpm-lock.yaml generated
View file

@ -8,6 +8,9 @@ importers:
.: .:
dependencies: dependencies:
'@fastify/cors':
specifier: ^9.0.1
version: 9.0.1
'@fastify/static': '@fastify/static':
specifier: ^7.0.4 specifier: ^7.0.4
version: 7.0.4 version: 7.0.4
@ -117,6 +120,9 @@ packages:
'@fastify/ajv-compiler@3.5.0': '@fastify/ajv-compiler@3.5.0':
resolution: {integrity: sha512-ebbEtlI7dxXF5ziNdr05mOY8NnDiPB1XvAlLHctRt/Rc+C3LCOVW5imUVX+mhvUhnNzmPBHewUkOFgGlCxgdAA==} resolution: {integrity: sha512-ebbEtlI7dxXF5ziNdr05mOY8NnDiPB1XvAlLHctRt/Rc+C3LCOVW5imUVX+mhvUhnNzmPBHewUkOFgGlCxgdAA==}
'@fastify/cors@9.0.1':
resolution: {integrity: sha512-YY9Ho3ovI+QHIL2hW+9X4XqQjXLjJqsU+sMV/xFsxZkE8p3GNnYVFpoOxF7SsP5ZL76gwvbo3V9L+FIekBGU4Q==}
'@fastify/error@3.4.1': '@fastify/error@3.4.1':
resolution: {integrity: sha512-wWSvph+29GR783IhmvdwWnN4bUxTD01Vm5Xad4i7i1VuAOItLvbPAb69sb0IQ2N57yprvhNIwAP5B6xfKTmjmQ==} resolution: {integrity: sha512-wWSvph+29GR783IhmvdwWnN4bUxTD01Vm5Xad4i7i1VuAOItLvbPAb69sb0IQ2N57yprvhNIwAP5B6xfKTmjmQ==}
@ -410,10 +416,16 @@ packages:
resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==}
engines: {node: '>=16 || 14 >=14.17'} engines: {node: '>=16 || 14 >=14.17'}
mnemonist@0.39.6:
resolution: {integrity: sha512-A/0v5Z59y63US00cRSLiloEIw3t5G+MiKz4BhX21FI+YBJXBOGW0ohFxTxO08dsOYlzxo87T7vGfZKYp2bcAWA==}
npm-run-path@2.0.2: npm-run-path@2.0.2:
resolution: {integrity: sha512-lJxZYlT4DW/bRUtFh1MQIWqmLwQfAxnqWG4HhEdjMlkrJYnJn0Jrr2u3mgxqaWsdiBc76TYkTG/mhrnYTuzfHw==} resolution: {integrity: sha512-lJxZYlT4DW/bRUtFh1MQIWqmLwQfAxnqWG4HhEdjMlkrJYnJn0Jrr2u3mgxqaWsdiBc76TYkTG/mhrnYTuzfHw==}
engines: {node: '>=4'} engines: {node: '>=4'}
obliterator@2.0.4:
resolution: {integrity: sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ==}
on-exit-leak-free@2.1.2: on-exit-leak-free@2.1.2:
resolution: {integrity: sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==} resolution: {integrity: sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==}
engines: {node: '>=14.0.0'} engines: {node: '>=14.0.0'}
@ -681,6 +693,11 @@ snapshots:
ajv-formats: 2.1.1(ajv@8.16.0) ajv-formats: 2.1.1(ajv@8.16.0)
fast-uri: 2.4.0 fast-uri: 2.4.0
'@fastify/cors@9.0.1':
dependencies:
fastify-plugin: 4.5.1
mnemonist: 0.39.6
'@fastify/error@3.4.1': {} '@fastify/error@3.4.1': {}
'@fastify/fast-json-stringify-compiler@4.3.0': '@fastify/fast-json-stringify-compiler@4.3.0':
@ -989,10 +1006,16 @@ snapshots:
minipass@7.0.4: {} minipass@7.0.4: {}
mnemonist@0.39.6:
dependencies:
obliterator: 2.0.4
npm-run-path@2.0.2: npm-run-path@2.0.2:
dependencies: dependencies:
path-key: 2.0.1 path-key: 2.0.1
obliterator@2.0.4: {}
on-exit-leak-free@2.1.2: {} on-exit-leak-free@2.1.2: {}
p-comuns@git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_comuns.git#ac72e915630a0f7750630a24389367141b0e8ae0(typescript@5.4.3): p-comuns@git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_comuns.git#ac72e915630a0f7750630a24389367141b0e8ae0(typescript@5.4.3):