CORS Issue
Answered
Great golden digger wasp posted this in #help-forum
Great golden digger waspOP
I don't know how to make an api public in next js so everyone can use it when I host. I tried the documentation method but it doesn't work either. Any solution please.
Answered by Double-striped Thick-knee
have you tried this,?? it should work
/** @type {import('next').NextConfig} */
const nextConfig = {
async headers() {
return [
{
// matching all API routes
source: "/api/:path*",
headers: [{ key: "Access-Control-Allow-Origin", value: "*" }],
},
];
},
};
export default nextConfig;5 Replies
@Double-striped Thick-knee have you tried this,
https://blog.logrocket.com/using-cors-next-js-handle-cross-origin-requests/
Great golden digger waspOP
this is not working
@Great golden digger wasp this is not working
Double-striped Thick-knee
have you tried this,?? it should work
/** @type {import('next').NextConfig} */
const nextConfig = {
async headers() {
return [
{
// matching all API routes
source: "/api/:path*",
headers: [{ key: "Access-Control-Allow-Origin", value: "*" }],
},
];
},
};
export default nextConfig;Answer
@Double-striped Thick-knee have you tried this,?? it should work
ts
/** @type {import('next').NextConfig} */
const nextConfig = {
async headers() {
return [
{
// matching all API routes
source: "/api/:path*",
headers: [{ key: "Access-Control-Allow-Origin", value: "*" }],
},
];
},
};
export default nextConfig;
Great golden digger waspOP
thank you so much
it is working