From 5017c5a5f108962dcf8b6668d8cc40e23a13378a Mon Sep 17 00:00:00 2001 From: Geometrically <18202329+Geometrically@users.noreply.github.com> Date: Fri, 28 May 2021 10:19:13 -0700 Subject: [PATCH] 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 --- app/router.scrollBehavior.js | 3 ++ layouts/default.vue | 2 +- layouts/error.vue | 3 -- middleware/analytics.js | 26 +++++++----- middleware/auth.js | 2 +- nuxt.config.js | 1 + pages/dashboard.vue | 2 +- pages/dashboard/follows.vue | 14 +++---- pages/dashboard/misc/revoke-token.vue | 2 +- pages/dashboard/moderation.vue | 25 ++++-------- pages/dashboard/notifications.vue | 13 +++--- pages/dashboard/projects.vue | 9 ++-- pages/dashboard/settings.vue | 9 ++-- pages/mod/_id.vue | 43 ++++++++------------ pages/mod/_id/edit.vue | 28 +++++-------- pages/mod/_id/newversion.vue | 14 +++---- pages/mod/_id/settings.vue | 52 ++++++++++-------------- pages/mod/_id/version/_version/edit.vue | 12 +++--- pages/mod/_id/version/_version/index.vue | 24 ++++------- pages/mod/create.vue | 17 ++++---- pages/mods.vue | 15 +++---- pages/report/create.vue | 13 ++---- pages/user/_id.vue | 13 ++---- store/auth.js | 2 +- store/user.js | 2 +- 25 files changed, 137 insertions(+), 209 deletions(-) create mode 100644 app/router.scrollBehavior.js diff --git a/app/router.scrollBehavior.js b/app/router.scrollBehavior.js new file mode 100644 index 000000000..d70bb5021 --- /dev/null +++ b/app/router.scrollBehavior.js @@ -0,0 +1,3 @@ +export default function (to, from, savedPosition) { + return savedPosition || { x: 0, y: 0 } +} diff --git a/layouts/default.vue b/layouts/default.vue index 4246c56bc..d986b0b6d 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -199,7 +199,7 @@ export default { }, computed: { authUrl() { - return `https://api.modrinth.com/api/v1/auth/init?url=${process.env.domain}${this.$route.fullPath}` + return `${this.$axios.defaults.baseURL}auth/init?url=${process.env.domain}${this.$route.fullPath}` }, userUrl() { return `/user/${this.$auth.user.id}` diff --git a/layouts/error.vue b/layouts/error.vue index 00e238b82..fcc7b0bcf 100644 --- a/layouts/error.vue +++ b/layouts/error.vue @@ -31,9 +31,6 @@ export default { }, }, layout: 'home', - created() { - // console.log(this.error) - }, } diff --git a/middleware/analytics.js b/middleware/analytics.js index 1a2aa8fd5..4d86c7193 100644 --- a/middleware/analytics.js +++ b/middleware/analytics.js @@ -1,5 +1,8 @@ import axios from 'axios' -export default async function (context) { +export default function (context) { + if (context.$config.analytics.base_url == null) { + return + } let domain = '' if (process.server) { domain = context.req.headers.host @@ -8,13 +11,16 @@ export default async function (context) { } const url = context.$config.analytics.base_url + '/register/visit' const path = context.route.path.split('?')[0] - try { - return await axios.post(url, { - path, - domain, - consent: false, - }) - } catch (e) { - // Simply silence the issue. - } + setTimeout(() => { + axios + .post(url, { + path, + domain, + consent: false, + }) + .then(() => {}) + .catch((e) => { + console.error('An error occurred while registering the visit: ', e) + }) + }) } diff --git a/middleware/auth.js b/middleware/auth.js index f1db0f50a..12c3e8f16 100644 --- a/middleware/auth.js +++ b/middleware/auth.js @@ -37,7 +37,7 @@ export default async function (context) { if (!context.$auth.user) { return context.redirect( - `https://api.modrinth.com/api/v1/auth/init?url=${process.env.domain}${context.route.fullPath}` + `${context.$axios.defaults.baseURL}auth/init?url=${process.env.domain}${context.route.fullPath}` ) } } diff --git a/nuxt.config.js b/nuxt.config.js index 6af80c1b7..07717e169 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -134,6 +134,7 @@ export default { ** See https://axios.nuxtjs.org/options */ axios: { + baseURL: 'https://api.modrinth.com/api/v1/', headers: { common: { Accept: 'application/json', diff --git a/pages/dashboard.vue b/pages/dashboard.vue index d4234dfa5..fef49e81b 100644 --- a/pages/dashboard.vue +++ b/pages/dashboard.vue @@ -81,7 +81,7 @@ export default { }, computed: { authUrl() { - return `https://api.modrinth.com/api/v1/auth/init?url=${process.env.domain}${this.$route.fullPath}` + return `${this.$axios.defaults.baseURL}auth/init?url=${process.env.domain}${this.$route.fullPath}` }, }, } diff --git a/pages/dashboard/follows.vue b/pages/dashboard/follows.vue index efdcd4d9e..799fe18d4 100644 --- a/pages/dashboard/follows.vue +++ b/pages/dashboard/follows.vue @@ -46,8 +46,6 @@