Next.js Discord

Discord Forum

CROS ERROR

Unanswered
hamdysaad20 posted this in #help-forum
Open in Discord
i'm working rn on a side project that can show a linked in job posts in the website, i added a NPM pakage :(https://www.npmjs.com/package/linkedin-jobs-api)
and when i tried to use it there is a problem :
Access to XMLHttpRequest at 'https://www.linkedin.com/jobs-guest/jobs/api/seeMoreJobPostings/search?keywords=software+engineer&location=Egypt&f_TPR=r604800&f_SB2=1&f_E=2&f_WT=3&f_JT=F&start=0' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What should i do in the next config ?
   async rewrites() {
        return [
            {
                source: '/api/:path*',
                destination: 'https://www.linkedin.com/:path*',
            },
        ]
    },

19 Replies

If you fetch from your client, you'll get cors errors. You'd need to fetch from the server.
the thing is there is a link to a page that is not JSON file it's a HTML and it has the data that i need
@Marchy no it's a normal html
you can't just request html from a URL, that's what cors protection is for
oh
This is the link that get prented into my consol
I didn't see the API part 🤔 interesting. But still needs to be fetched from the server, so either getServerSideProps or in a server component in the app directory
Aha i guss that i need to try the server side propse since i use a package that not mine
I'm kinda shocked that linkedin provides an html endpoint 😂 I guess they want people to scrape their site
Or maybe creating a custom script that extract the data from the html
And its very different
You could just scrape it with something like puppeteer
but that can get kinda expensive unless you're doing it in batch
@Marchy You could just scrape it with something like puppeteer
That's a hard choice 😂