How to enable cors policy at node server #6
-
|
I am using Node as Backend. And there I get Cors-Policy Error. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
You can fix that when you use Express like this. //EXPRESS |
Beta Was this translation helpful? Give feedback.
-
|
Okay, I will try that :) Thanks for your time, |
Beta Was this translation helpful? Give feedback.
-
|
No, fixed right now :) Great work~ |
Beta Was this translation helpful? Give feedback.
You can fix that when you use Express like this.
//EXPRESS
const app = express();
if (process.env.NODE_ENV == "production") app.use(enforce.HTTPS({ trustProtoHeader: true }));
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors({
origin: '',
methods: ['GET', 'POST', 'DELETE', 'UPDATE', 'PUT', 'PATCH'],
credentials: true
}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, './FE/build')));
app.get("", (req, res) => {
res.sendFile(path.join(__dirname, './FE/build', 'index.html'));
});