自己學la
香港地讀master晒錢
app.use(
cors({
origin: "*", // Or specify origins you want to allow
methods: ["GET", "POST", "PUT", "DELETE"],
allowedHeaders: ["Content-Type", "Authorization"], // Add other headers you need to allow
})
);
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); // This allows all origins
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
next();
});
const fetchHomeData = async () => {
try {
const response = await axios.get(apiUrl, {
params: {
organizationID: organizationId,
},
headers: {
"Content-Type": "application/json",
},
});
console.log("Retrieved Home Page Data: ", response.data);
setPopular(response.data.popular);
setTop5(response.data.topfive);
setCategory(response.data.category);
} catch (error) {
console.error("Error fetching menu data:", error);
}
};