From 9b1753610221758cdd2ef424a3189a6bce65ee49 Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Thu, 7 Oct 2021 10:22:07 +1300 Subject: [PATCH] Add axios library to frontend with base repository --- frontend/package-lock.json | 17 +++++++++++++++++ frontend/package.json | 1 + frontend/src/config.js | 1 + frontend/src/repository/Repository.js | 14 ++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 frontend/src/config.js create mode 100644 frontend/src/repository/Repository.js diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 3568519..546f53b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -11,6 +11,7 @@ "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", + "axios": "^0.22.0", "bootstrap": "^5.1.2", "node-sass": "^6.0.1", "react": "^17.0.2", @@ -4712,6 +4713,14 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.22.0.tgz", + "integrity": "sha512-Z0U3uhqQeg1oNcihswf4ZD57O3NrR1+ZXhxaROaWpDmsDTx7T2HNBV2ulBtie2hwJptu8UvgnJoK+BIqdzh/1w==", + "dependencies": { + "follow-redirects": "^1.14.4" + } + }, "node_modules/axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", @@ -26538,6 +26547,14 @@ "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.3.3.tgz", "integrity": "sha512-/lqqLAmuIPi79WYfRpy2i8z+x+vxU3zX2uAm0gs1q52qTuKwolOj1P8XbufpXcsydrpKx2yGn2wzAnxCMV86QA==" }, + "axios": { + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.22.0.tgz", + "integrity": "sha512-Z0U3uhqQeg1oNcihswf4ZD57O3NrR1+ZXhxaROaWpDmsDTx7T2HNBV2ulBtie2hwJptu8UvgnJoK+BIqdzh/1w==", + "requires": { + "follow-redirects": "^1.14.4" + } + }, "axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 87dfdcf..9b0bca4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", + "axios": "^0.22.0", "bootstrap": "^5.1.2", "node-sass": "^6.0.1", "react": "^17.0.2", diff --git a/frontend/src/config.js b/frontend/src/config.js new file mode 100644 index 0000000..879120f --- /dev/null +++ b/frontend/src/config.js @@ -0,0 +1 @@ +export const API_URL = "http://localhost:8000"; diff --git a/frontend/src/repository/Repository.js b/frontend/src/repository/Repository.js new file mode 100644 index 0000000..135c84b --- /dev/null +++ b/frontend/src/repository/Repository.js @@ -0,0 +1,14 @@ +import axios from "axios" +import { API_URL } from "../config"; + +// Base URL used by all requests +const baseUrl = API_URL; + +// Create the axios object +const repo = axios.create({ + baseURL: baseUrl, +}); + +repo.defaults.headers.post["access-control-allow-origin"] = "*"; + +export default repo;