-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting error #33
Comments
Hello, how did you fix it? |
any solve? |
Basically need cors to work import * as cheerio from "cheerio";
import express from "express";
var cors = require("cors");
const app = express();
app.use(cors());
// cheerio is used for faster implementation
// https://www.npmjs.com/package/cheerio
// editorjs link previewer
app.get("/fetchUrl", async (req, res) => {
let url = req.query.url as string;
let resHTML = await fetch(new URL(url)).catch((e) => console.log(e));
if (!resHTML) {
res.status(500).json({
success: 0,
meta: {},
});
return;
}
const html = await resHTML.text();
const $ = cheerio.load(html);
// custom meta-tag function
const getMetaTag = (value: string) => {
return (
$(`meta[name=${value}]`).attr("content") ||
$(`meta[property="og:${value}"]`).attr("content") ||
$(`meta[property="twitter:${value}"]`).attr("content")
);
};
const metadataObject = {
success: 1,
meta: {
title: $("title").first().text(),
description: getMetaTag("description"),
image: {
url: getMetaTag("image"),
},
},
};
res.send(metadataObject);
return;
});
app.listen(80, function () {
console.log('All CORS Requests-enabled web server listening on port 80')
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://pravosleva.ru/express-helper/url-metadata/editorjs?url=https%3A%2F%2Fgoogle.com. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
The text was updated successfully, but these errors were encountered: