Skip to content

Commit 6a4a967

Browse files
committed
fix: remove cors
1 parent 662ad79 commit 6a4a967

File tree

3 files changed

+5
-54
lines changed

3 files changed

+5
-54
lines changed

Backend/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const app = express();
2828
// },
2929
// };
3030

31-
// app.use(cors(corsOptions));
31+
app.use(cors());
3232
app.use(bodyParser.urlencoded({ extended: true }));
3333
app.use("/auth", auth);
3434
app.use(aiml);

Backend/routes/aiml.js

+1-27
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,8 @@ const router = express.Router();
99
router.use(cookieParser());
1010
router.use(bodyParser.urlencoded({ extended: true }));
1111

12-
var whitelist = [
13-
"https://ao3-chrome-extension-website.vercel.app/",
14-
"chrome-extension://nnmmeljlhmhpnfphcpifdahblfmhlilm",
15-
"http://localhost:5173",
16-
"http://localhost:5174",
17-
"*"
18-
];
19-
20-
var corsOptions = {
21-
origin: function (origin, callback) {
22-
console.log("Request Origin:", origin);
23-
if (whitelist.indexOf(origin) !== -1 || !origin) {
24-
callback(null, true);
25-
} else {
26-
callback(new Error("Not allowed by CORS"));
27-
}
28-
},
29-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // Allow all required HTTP methods
30-
allowedHeaders: ['Content-Type', 'Authorization'], // Allow necessary headers
31-
credentials: true, // Allow credentials if needed (cookies, HTTP auth, etc.)
32-
};
33-
34-
// Handle preflight requests for all routes
35-
router.options('*', cors(corsOptions));
36-
37-
3812
// api routes
39-
router.get('/recom', cors(corsOptions),verify_token, get_recommendations);
13+
router.get('/recom',verify_token, get_recommendations);
4014
// router.get("/test",(req,res)=>{res.send({"status":"ok"})});
4115

4216
export default router;

Backend/routes/auth.js

+3-26
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,12 @@ import cors from "cors";
88
const router = express.Router();
99
router.use(bodyParser.urlencoded({extended: true}));
1010

11-
var whitelist = [
12-
"https://ao3-chrome-extension-website.vercel.app/",
13-
"chrome-extension://nnmmeljlhmhpnfphcpifdahblfmhlilm",
14-
"http://localhost:5173",
15-
"http://localhost:5174",
16-
"*"
17-
];
1811

19-
var corsOptions = {
20-
origin: function (origin, callback) {
21-
console.log("Request Origin:", origin);
22-
if (whitelist.indexOf(origin) !== -1 || !origin) {
23-
callback(null, true);
24-
} else {
25-
callback(new Error("Not allowed by CORS"));
26-
}
27-
},
28-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // Allow all required HTTP methods
29-
allowedHeaders: ['Content-Type', 'Authorization'], // Allow necessary headers
30-
credentials: true, // Allow credentials if needed (cookies, HTTP auth, etc.)
31-
};
32-
33-
// Handle preflight requests for all routes
34-
router.options('*', cors(corsOptions));
3512
//login routes
3613
// router.get("/login", func.get_login); //use this when using the register file with backend
37-
router.post("/login", cors(corsOptions),func.post_login);
38-
router.post("/register", hashPassword,cors(corsOptions) ,func.post_register);
14+
router.post("/login",func.post_login);
15+
router.post("/register", hashPassword,func.post_register);
3916
router.get("/token/:token",func.get_token);
40-
router.get("/validate",cors(corsOptions), verify_token,func.get_verify);
17+
router.get("/validate", verify_token,func.get_verify);
4118

4219
export default router;

0 commit comments

Comments
 (0)