Use base URL for axios (#241)

* Switch site to use axios base url

* Fix team invites

* Fix find/replace setting the wrong thing

* Fix analytics being blocking, small issues
This commit is contained in:
Geometrically
2021-05-28 10:19:13 -07:00
committed by GitHub
parent 03cbab5267
commit 5017c5a5f1
25 changed files with 137 additions and 209 deletions

View File

@@ -46,8 +46,6 @@
</template>
<script>
import axios from 'axios'
import ModCard from '~/components/ui/ProjectCard'
import FollowIcon from '~/assets/images/utils/heart.svg?inline'
import FollowIllustration from '~/assets/images/illustrations/follow_illustration.svg?inline'
@@ -59,15 +57,13 @@ export default {
FollowIllustration,
},
async asyncData(data) {
const res = await axios.get(
`https://api.modrinth.com/api/v1/user/${data.$auth.user.id}/follows`,
const res = await data.$axios.get(
`user/${data.$auth.user.id}/follows`,
data.$auth.headers
)
const mods = (
await axios.get(
`https://api.modrinth.com/api/v1/mods?ids=${JSON.stringify(res.data)}`
)
await data.$axios.get(`mods?ids=${JSON.stringify(res.data)}`)
).data.sort((a, b) => a.title > b.title)
return {
@@ -76,8 +72,8 @@ export default {
},
methods: {
async unfavMod(index) {
await axios.delete(
`https://api.modrinth.com/api/v1/mod/${this.mods[index].id}/follow`,
await this.$axios.delete(
`mod/${this.mods[index].id}/follow`,
this.$auth.headers
)

View File

@@ -54,7 +54,7 @@ export default {
async logout() {
this.$cookies.set('auth-token-reset', true)
await this.$router.replace(
`https://api.modrinth.com/api/v1/auth/init?url=${process.env.domain}${this.$route.fullPath}`
`auth/init?url=${process.env.domain}${this.$route.fullPath}`
)
},
},

View File

@@ -87,8 +87,6 @@
</template>
<script>
import axios from 'axios'
import ModCard from '~/components/ui/ProjectCard'
import Security from '~/assets/images/illustrations/security.svg?inline'
@@ -98,19 +96,10 @@ export default {
Security,
},
async asyncData(data) {
const mods = (
await axios.get(
`https://api.modrinth.com/api/v1/moderation/mods`,
data.$auth.headers
)
).data
const mods = (await data.$axios.get(`moderation/mods`, data.$auth.headers))
.data
const reports = (
await axios.get(
`https://api.modrinth.com/api/v1/report`,
data.$auth.headers
)
).data
const reports = (await data.$axios.get(`report`, data.$auth.headers)).data
return {
mods,
@@ -119,8 +108,8 @@ export default {
},
methods: {
async changeModStatus(id, status, index) {
await axios.patch(
`https://api.modrinth.com/api/v1/mod/${id}`,
await this.$axios.patch(
`mod/${id}`,
{
status,
},
@@ -130,8 +119,8 @@ export default {
this.mods.splice(index, 1)
},
async deleteReport(index) {
await axios.delete(
`https://api.modrinth.com/api/v1/report/${this.reports[index].id}`,
await this.$axios.delete(
`report/${this.reports[index].id}`,
this.$auth.headers
)

View File

@@ -52,7 +52,6 @@
</template>
<script>
import axios from 'axios'
import UpToDate from '~/assets/images/illustrations/up_to_date.svg?inline'
export default {
@@ -61,8 +60,8 @@ export default {
},
async asyncData(data) {
const notifications = (
await axios.get(
`https://api.modrinth.com/api/v1/user/${data.$auth.user.id}/notifications`,
await data.$axios.get(
`user/${data.$auth.user.id}/notifications`,
data.$auth.headers
)
).data.sort((a, b) => new Date(b.created) - new Date(a.created))
@@ -79,17 +78,17 @@ export default {
if (index) {
const config = {
method: notification.actions[index].action_route[0].toLowerCase(),
url: `https://api.modrinth.com/api/v1/${notification.actions[index].action_route[1]}`,
url: `${notification.actions[index].action_route[1]}`,
headers: {
Authorization: this.$auth.token,
},
}
await axios(config)
await this.$axios(config)
}
await axios.delete(
`https://api.modrinth.com/api/v1/notification/${notification.id}`,
await this.$axios.delete(
`notification/${notification.id}`,
this.$auth.headers
)

View File

@@ -46,7 +46,6 @@
</template>
<script>
import axios from 'axios'
import ModCard from '~/components/ui/ProjectCard'
import UpToDate from '~/assets/images/illustrations/up_to_date.svg?inline'
@@ -56,13 +55,13 @@ export default {
UpToDate,
},
async asyncData(data) {
let res = await axios.get(
`https://api.modrinth.com/api/v1/user/${data.$auth.user.id}/mods`,
let res = await data.$axios.get(
`user/${data.$auth.user.id}/mods`,
data.$auth.headers
)
res = await axios.get(
`https://api.modrinth.com/api/v1/mods?ids=${JSON.stringify(res.data)}`,
res = await data.$axios.get(
`mods?ids=${JSON.stringify(res.data)}`,
data.$auth.headers
)

View File

@@ -115,7 +115,6 @@
</template>
<script>
import axios from 'axios'
import ConfirmPopup from '~/components/ui/ConfirmPopup'
export default {
@@ -167,8 +166,8 @@ export default {
bio: this.bio,
}
await axios.patch(
`https://api.modrinth.com/api/v1/user/${this.$auth.user.id}`,
await this.$axios.patch(
`user/${this.$auth.user.id}`,
data,
this.$auth.headers
)
@@ -191,8 +190,8 @@ export default {
this.$nuxt.$loading.start()
try {
await axios.delete(
`https://api.modrinth.com/api/v1/user/${this.$auth.user.id}`,
await this.$axios.delete(
`user/${this.$auth.user.id}`,
this.$auth.headers
)
} catch (err) {