Skip to content

Commit

Permalink
check both local and remote urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanov N committed Dec 15, 2024
1 parent 941f9c3 commit a043b01
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/store/plugins/navigatorOnline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { i18n } from '@/i18n'
import axios from 'axios'

const checkUrl = 'robots.txt'
const checkUrlLocal = 'robots.txt'
const checkUrlRemote = 'https://ipv4.icanhazip.com'

export default (store) => {
// window.addEventListener('online', handleEvent)
Expand Down Expand Up @@ -32,15 +33,28 @@ export default (store) => {

const inetConnectionCheck = async () => {
try {
const res = await axios.get(`${checkUrl}`, {
const reqLocal = await axios.get(`${checkUrlLocal}`, {
headers: {
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: '0'
}
})
return res.status >= 200 && res.status < 300
return reqLocal.status >= 200 && reqLocal.status < 300
} catch (err) {
if (err.code === 'ERR_NETWORK') return false
if (err.code === 'ERR_NETWORK') {
try {
const reqRemote = await axios.get(`${checkUrlRemote}`, {
headers: {
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: '0'
}
})
return reqRemote.status >= 200 && reqRemote.status < 300
} catch (err) {
if (err.code === 'ERR_NETWORK') return false
}
}
}
}

0 comments on commit a043b01

Please sign in to comment.