Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Access to fetch at [URL] from origin [URL] has been blocked by CORS Policy.
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- const cors = require('cors')({ origin: true });
- app.get('/my-route', (req, res) => {
- return cors(req, res, () => {
- res.render('view-report-template', context, (err, html) => {
- res.status(200).send(html);
- });
- });
- const cors = require('cors')({ origin: true });
- app.get('/my-route', (req, res) => {
- res.render('view-report-template', context, (err, html) => {
- res.status(200).send(html);
- });
- });
- app.use(cors);
- app.use((req, res, next) => {
- res.header("Access-Control-Allow-Origin", "*");
- res.header('Access-Control-Allow-Methods', 'DELETE, PUT, GET, POST');
- res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With,
- Content-Type, Accept");
- next();
- });
- app.get('/my-route', (req, res) => {
- res.render('view-report-template', context, (err, html) => {
- res.status(200).send(html);
- });
- });
- app.use((req, res, next) => {
- res.header("Access-Control-Allow-Origin", "*")
- res.header(
- "Access-Control-Allow-Headers",
- "Origin, X-Requested-With, Content-Type, Accept, Authorization"
- );
- if(req.method === 'OPTIONS'){
- res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH,
- DELETE, GET');
- return res.status(200).json({});
- }
- next();
- });
- app.get('/my-route', (req, res) => {
- res.render('view-report-template', context, (err, html) => {
- res.status(200).send(html);
- });
- });
- app.get('/my-route', (req, res) => {
- res.set('Access-Control-Allow-Origin', '*');
- res.status(200).send(html);
- });
- fetch('https://us-central1-[project-id].cloudfunctions.net/my-route', {
- method: "GET",
- mode: "cors"
- })
- .then(res => res.text())
- .then(data => console.log(data));
Add Comment
Please, Sign In to add comment