Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Restaurando configurações do cors para deploy #17

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@ const { generateFinancialReportCSV } = require("./Models/csvGenerator");
const app = express();

// Variáveis de ambiente
const { NODE_ENV, MONGO_URI, OFFICIAL_MONGO_URI, PORT } = process.env;
const { NODE_ENV, MONGO_URI, OFFICIAL_MONGO_URI, PORT, FRONT_HOST } =
process.env;

console.log("Ambiente:", NODE_ENV);
console.log("MONGO_URI:", MONGO_URI);
console.log("OFFICIAL_MONGO_URI:", OFFICIAL_MONGO_URI);

// Middleware
const allowedOrigins = [
"http://localhost:5173",
"https://devel--appsentinela.netlify.app",
"https://appsentinela.netlify.app",
];
app.use(
cors({
origin: function (origin, callback) {
if (!origin || allowedOrigins.indexOf(origin) !== -1) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
})
);
const corsOption = {
origin: (origin, callback) => {
const allowedOrigin = FRONT_HOST || "localhost";
if (origin?.includes(allowedOrigin) || origin === undefined) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
};

// Aplicar o middleware CORS antes das rotas
app.use(cors(corsOption));

app.use(bodyParser.json());

Expand Down
Loading