Modrinth/middleware/analytics.js
Geometrically 5017c5a5f1
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
2021-05-28 10:19:13 -07:00

27 lines
617 B
JavaScript

import axios from 'axios'
export default function (context) {
if (context.$config.analytics.base_url == null) {
return
}
let domain = ''
if (process.server) {
domain = context.req.headers.host
} else {
domain = location.host
}
const url = context.$config.analytics.base_url + '/register/visit'
const path = context.route.path.split('?')[0]
setTimeout(() => {
axios
.post(url, {
path,
domain,
consent: false,
})
.then(() => {})
.catch((e) => {
console.error('An error occurred while registering the visit: ', e)
})
})
}