Skip to content

Commit

Permalink
Netlify deploys preview support
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsume-197 committed Sep 3, 2024
1 parent 7cbfa75 commit 1b2a770
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ newrelic.instrumentLoadedModule("express", express);

const app: Application = express();

const allowedOrigins = ["http://localhost:5173", "https://db.brigadasos.xyz", "https://db.dev.brigadasos.xyz", "https://nadeshiko.co", "https://dev.nadeshiko.co", "http://localhost:3000"];
const allowedOrigins = process.env.ALLOWED_WEBSITE_URLS || '';
const netlifyPattern = /^https:\/\/deploy-preview-\d+--nadeshiko\.netlify\.app$/;

app.use(function (req, res, next) {
// Obtiene el origen de la solicitud
const origin: string | undefined = req.headers.origin;

// Si el origen de la solicitud está en la lista de origines permitidos, establece el encabezado Access-Control-Allow-Origin
if (allowedOrigins.includes(origin as string)) {
if (allowedOrigins.includes(origin as string) || netlifyPattern.test(origin as string)) {
res.setHeader("Access-Control-Allow-Origin", origin as string);
}

Expand Down

0 comments on commit 1b2a770

Please sign in to comment.