Skip to content

Commit 0d7275d

Browse files
authored
Develop (#131)
2 parents 0fd2a30 + b5081b4 commit 0d7275d

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

backend/src/middleware/cors.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import cors from "cors";
22

3+
// Regex cobre qualquer preview do Vercel: painel-vagas-*.vercel.app
4+
// (hash-based e branch-based, ex: git-master-bene-teslas-projects)
5+
const VERCEL_PREVIEW_RE = /^https:\/\/painel-vagas-[a-z0-9-]+\.vercel\.app$/;
6+
37
const DEFAULT_ALLOWED_ORIGINS = [
48
"https://painel-vagas-lake.vercel.app",
9+
"https://painel-vagas-git-master-bene-teslas-projects.vercel.app",
10+
"https://painel-vagas-m6hbzlqeh-bene-teslas-projects.vercel.app",
511
"https://jobsglobalscraper.ddns.net",
6-
"http://jobsglobalscraper.ddns.net",
712
"http://localhost:5173",
813
"http://localhost:5174",
914
];
@@ -18,19 +23,14 @@ function parseAllowedOrigins(value: string | undefined): Set<string> {
1823

1924
export const corsOptions: cors.CorsOptions = {
2025
origin(origin, callback) {
21-
const allowedOrigins = parseAllowedOrigins(
22-
process.env.CORS_ALLOWED_ORIGINS,
23-
);
24-
2526
if (!origin) return callback(null, true);
2627

27-
if (/^https:\/\/painel-vagas-[a-z0-9-]+\.vercel\.app$/.test(origin)) {
28-
return callback(null, true);
29-
}
28+
if (VERCEL_PREVIEW_RE.test(origin)) return callback(null, true);
3029

30+
const allowedOrigins = parseAllowedOrigins(process.env.CORS_ALLOWED_ORIGINS);
3131
if (allowedOrigins.has(origin)) return callback(null, true);
3232

33-
callback(new Error(`Origin not allowed by CORS: ${origin}`));
33+
callback(new Error("Origin not allowed by CORS"));
3434
},
3535
methods: ["GET", "POST", "PATCH", "DELETE", "OPTIONS"],
3636
allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"],

frontend/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"rewrites": [
33
{
44
"source": "/api/(.*)",
5-
"destination": "http://jobsglobalscraper.ddns.net/api/$1"
5+
"destination": "https://jobsglobalscraper.ddns.net/api/$1"
66
},
77
{
88
"source": "/(.*)",

vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"rewrites": [
33
{
44
"source": "/api/(.*)",
5-
"destination": "http://jobsglobalscraper.ddns.net/api/$1"
5+
"destination": "https://jobsglobalscraper.ddns.net/api/$1"
66
},
77
{
88
"source": "/((?!api/).*)",

0 commit comments

Comments
 (0)