edivad99 / njs-ergastf1api Goto Github PK
View Code? Open in Web Editor NEWConversion of the ergast.com API from PHP to nodeJS
Conversion of the ergast.com API from PHP to nodeJS
Thanks for your work on this. I have forked the repository with the intention of decoupling the API from the database.
Are there any features in the PHP implementation that are missing? I could implement them if there are.
Docker mysql container does not work for Apple Silicon, consider switching to MariaDB?
AJAX calls via axios fail due to cors issues.
Request
curl 'http://localhost:8080/races?year=2021' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'DNT: 1' \
-H 'Origin: http://localhost:3000' \
-H 'Pragma: no-cache' \
-H 'Referer: http://localhost:3000/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-site' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
--compressed
Response Headers
Request URL: http://localhost:8080/races?year=2021
Request Method: GET
Status Code: 400
Referrer Policy: strict-origin-when-cross-origin
First of all, thank you for this node.js based API of ErgastAPI.
I'm successfully running the API in Docker using domain localhost:8080
Unfortunately the REST API is blocked by CORS while loading it in my react app.
Exact error is:
VM1514:1 Access to XMLHttpRequest at 'localhost:8080/drivers' from origin 'http://localhost:3000' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
This is my code so far. I've already tried to add CORS header but that doesn't effect anything.
Can you please help me out a bit?
function App() {
useEffect(() => {
let ignore = false;
async function fetchData() {
const result = await axios("localhost:8080/drivers", {
headers: {
"Access-Control-Allow-Origin": "*"
}
});
if (!ignore) setData(result.data);
console.log(result);
}
fetchData();
});
}
Hi Davide,
Not sure of the best way to contact you so I hope you see this.
I have taken the liberty to create a NodeJS implementation based on the one you have here.
https://github.com/StraightOuttaCrompton/ergast-api
My goal has been to use industry best practices to help make the api easier to maintain a develop. It is written in TypeScript and uses the NestJS framework. I have also written some test to ensure that the migration has been done succesfully with no regressions.
I am hoping you could take a look and let me know your thoughts.
Many thanks,
StraightOuttaCrompton
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.