Skip to content

Commit 9bb183b

Browse files
committed
feat: use axios for ssr
1 parent 9f4bfcb commit 9bb183b

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

lib/use-contentful.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ref } from 'vue'
2+
import axios from 'axios'
23

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

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

23-
const options: RequestInit = {
24-
method: 'POST',
25-
headers: {
26-
Authorization: `Bearer ${token}`,
27-
'Content-Type': 'application/json',
28-
},
29-
body: JSON.stringify({ query }),
30-
}
31-
32-
fetch(URI, options)
33-
.then((response) => response.json() as Promise<ContentfulResponse<T>>)
24+
axios
25+
.post<ContentfulResponse<T>>(URI, {
26+
headers: {
27+
Authorization: `Bearer ${token}`,
28+
'Content-Type': 'application/json',
29+
},
30+
body: JSON.stringify({ query }),
31+
})
32+
.then(({ data }) => data)
3433
.then(({ data: response, errors: contenfulErrors }) => {
3534
isLoading.value = false
3635

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@typescript-eslint/eslint-plugin": "5.15.0",
4848
"@typescript-eslint/parser": "5.15.0",
4949
"all-contributors-cli": "6.20.0",
50+
"axios": "^0.26.1",
5051
"concurrently": "7.0.0",
5152
"conventional-changelog-conventionalcommits": "4.6.3",
5253
"eslint": "8.11.0",
@@ -66,6 +67,7 @@
6667
"vue": "3.2.31"
6768
},
6869
"peerDependencies": {
70+
"axios": "^0.26.1",
6971
"vue": "^3.2.29"
7072
}
7173
}

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,13 @@ at-least-node@^1.0.0:
15231523
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
15241524
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
15251525

1526+
axios@^0.26.1:
1527+
version "0.26.1"
1528+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
1529+
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
1530+
dependencies:
1531+
follow-redirects "^1.14.8"
1532+
15261533
babel-jest@^27.5.1:
15271534
version "27.5.1"
15281535
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-27.5.1.tgz#a1bf8d61928edfefd21da27eb86a695bfd691444"
@@ -2580,6 +2587,11 @@ flatted@^3.1.0, flatted@^3.2.4:
25802587
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
25812588
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==
25822589

2590+
follow-redirects@^1.14.8:
2591+
version "1.14.9"
2592+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
2593+
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==
2594+
25832595
form-data@^3.0.0:
25842596
version "3.0.1"
25852597
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"

0 commit comments

Comments
 (0)