I'm using Express with EJS to render the response from a database query as an simple Html page. in dev tools shows an error
"Access to fetch at 'https://o189131.ingest.sentry.io/api/5478725/envelope/?sentry_key=504fcb6b9eee411d8157d41c0adb1170&sentry_version=7' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."
And it doesn't render Html page, I want to use keep the extension of ejs file like home.html instead of using home.ejs.html in visual studio but I cant, why?
const express = require('express')
const app = express()
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
res.render('home')
})
app.listen(3000, () => {
console.log("LISTENING ON PORT 3000")
})
Seems like a CORS error, which happens when your request is blocked by your browsers' same-origin policy. Try adding 'Access-Control-Allow-Origin: "*"' to your request header to bypass it:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
You can read more here.