Skip to content

Commit

Permalink
feat: use axios for ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenie committed Mar 21, 2022
1 parent 9f4bfcb commit 9bb183b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/use-contentful.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ref } from 'vue'
import axios from 'axios'

type ContentfulOptions = {
readonly spaceId: string
Expand All @@ -20,17 +21,15 @@ export const useContentful = <T>(

const URI = `https://graphql.contentful.com/content/v1/spaces/${spaceId}`

const options: RequestInit = {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
}

fetch(URI, options)
.then((response) => response.json() as Promise<ContentfulResponse<T>>)
axios
.post<ContentfulResponse<T>>(URI, {
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
})
.then(({ data }) => data)
.then(({ data: response, errors: contenfulErrors }) => {
isLoading.value = false

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@typescript-eslint/eslint-plugin": "5.15.0",
"@typescript-eslint/parser": "5.15.0",
"all-contributors-cli": "6.20.0",
"axios": "^0.26.1",
"concurrently": "7.0.0",
"conventional-changelog-conventionalcommits": "4.6.3",
"eslint": "8.11.0",
Expand All @@ -66,6 +67,7 @@
"vue": "3.2.31"
},
"peerDependencies": {
"axios": "^0.26.1",
"vue": "^3.2.29"
}
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,13 @@ at-least-node@^1.0.0:
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==

axios@^0.26.1:
version "0.26.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
dependencies:
follow-redirects "^1.14.8"

babel-jest@^27.5.1:
version "27.5.1"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-27.5.1.tgz#a1bf8d61928edfefd21da27eb86a695bfd691444"
Expand Down Expand Up @@ -2580,6 +2587,11 @@ flatted@^3.1.0, flatted@^3.2.4:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==

follow-redirects@^1.14.8:
version "1.14.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==

form-data@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
Expand Down

0 comments on commit 9bb183b

Please sign in to comment.