@dargmuesli/nuxt-vio 21.0.10 → 22.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.config/lint.js +1 -1
- package/app/composables/networking.ts +3 -1
- package/app/composables/testing.ts +10 -3
- package/app/utils/dateTime.ts +2 -2
- package/node/static/environment.ts +1 -0
- package/package.json +1 -1
- package/server/middleware/dateTime.ts +3 -2
- package/server/utils/dateTime.ts +25 -12
- package/server/utils/networking.ts +11 -7
- package/server/utils/testing.ts +23 -4
- package/shared/utils/networking.ts +20 -6
package/.config/lint.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const useGetServiceHref = () => {
|
|
2
2
|
const host = useHost()
|
|
3
3
|
const runtimeConfig = useRuntimeConfig()
|
|
4
|
+
const isTesting = useIsTesting()
|
|
4
5
|
|
|
5
6
|
return ({
|
|
6
7
|
isSsr = true,
|
|
@@ -8,12 +9,13 @@ export const useGetServiceHref = () => {
|
|
|
8
9
|
port,
|
|
9
10
|
}: {
|
|
10
11
|
isSsr?: boolean
|
|
11
|
-
name
|
|
12
|
+
name: string
|
|
12
13
|
port?: number
|
|
13
14
|
}) =>
|
|
14
15
|
getServiceHref({
|
|
15
16
|
host,
|
|
16
17
|
isSsr,
|
|
18
|
+
isTesting,
|
|
17
19
|
name,
|
|
18
20
|
port,
|
|
19
21
|
stagingHost: runtimeConfig.public.vio.stagingHost,
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
export const useIsTesting = (
|
|
2
|
-
|
|
1
|
+
export const useIsTesting = ({
|
|
2
|
+
isCookieEnabled = true,
|
|
3
|
+
}: { isCookieEnabled?: boolean } | undefined = {}) => {
|
|
3
4
|
const runtimeConfig = useRuntimeConfig()
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
const isTestingByRuntimeConfig = runtimeConfig.public.vio.isTesting
|
|
7
|
+
if (isTestingByRuntimeConfig) return true
|
|
8
|
+
|
|
9
|
+
if (isCookieEnabled) {
|
|
10
|
+
const isTestingByCookie = !!useCookie(TESTING_COOKIE_NAME).value
|
|
11
|
+
if (isTestingByCookie) return true
|
|
12
|
+
}
|
|
6
13
|
}
|
package/app/utils/dateTime.ts
CHANGED
package/package.json
CHANGED
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"url": "git+https://github.com/dargmuesli/vio.git"
|
|
98
98
|
},
|
|
99
99
|
"type": "module",
|
|
100
|
-
"version": "
|
|
100
|
+
"version": "22.0.0-beta.1",
|
|
101
101
|
"scripts": {
|
|
102
102
|
"build": "pnpm run build:node",
|
|
103
103
|
"build:node": "NUXT_PUBLIC_I18N_BASE_URL=https://app.localhost:3001 nuxt build playground",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export default defineEventHandler(async (event) => {
|
|
2
|
-
|
|
2
|
+
const isTesting = useIsTesting()
|
|
3
|
+
event.context.$timeZone = await getTimeZone({ event, isTesting })
|
|
3
4
|
})
|
|
4
5
|
|
|
5
6
|
declare module 'h3' {
|
|
6
7
|
interface H3EventContext {
|
|
7
|
-
$
|
|
8
|
+
$timeZone?: string
|
|
8
9
|
}
|
|
9
10
|
}
|
package/server/utils/dateTime.ts
CHANGED
|
@@ -1,28 +1,41 @@
|
|
|
1
1
|
import type { H3Event } from 'h3'
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
3
|
+
export const getTimeZone = async ({
|
|
4
|
+
event,
|
|
5
|
+
isTesting,
|
|
6
|
+
}: {
|
|
7
|
+
event: H3Event
|
|
8
|
+
isTesting?: boolean
|
|
9
|
+
}) => {
|
|
10
|
+
const timeZoneBySsr = event.context.$timeZone
|
|
5
11
|
|
|
6
|
-
if (
|
|
12
|
+
if (timeZoneBySsr) return timeZoneBySsr
|
|
7
13
|
|
|
8
|
-
const
|
|
14
|
+
const timeZoneByCookie = getCookie(event, TIMEZONE_COOKIE_NAME)
|
|
9
15
|
|
|
10
|
-
if (
|
|
16
|
+
if (timeZoneByCookie) return timeZoneByCookie
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
if (!isTesting) {
|
|
19
|
+
const ip = getRequestIP(event, { xForwardedFor: true })
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
if (ip) {
|
|
22
|
+
const timeZoneByIpApi = await getTimeZoneByIpApi({ ip })
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
if (timeZoneByIpApi) return timeZoneByIpApi
|
|
25
|
+
}
|
|
18
26
|
}
|
|
19
27
|
}
|
|
20
28
|
|
|
21
|
-
export const
|
|
22
|
-
|
|
29
|
+
export const useTimeZone = async () => {
|
|
30
|
+
const event = useEvent()
|
|
31
|
+
const isTesting = useIsTesting()
|
|
23
32
|
|
|
33
|
+
return await getTimeZone({ event, isTesting })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const getTimeZoneByIpApi = async ({ ip }: { ip: string }) => {
|
|
24
37
|
const ipApiResult = await $fetch<{ timezone: string }>(
|
|
25
|
-
`http://
|
|
38
|
+
`http://geoip:8080/${ip}`,
|
|
26
39
|
).catch(() => {})
|
|
27
40
|
|
|
28
41
|
if (ipApiResult) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { H3Event } from 'h3'
|
|
2
|
+
|
|
3
|
+
export const useGetServiceHref = ({ event }: { event?: H3Event } = {}) => {
|
|
4
|
+
const host = useHost({ event })
|
|
3
5
|
const runtimeConfig = useRuntimeConfig()
|
|
6
|
+
const isTesting = useIsTesting()
|
|
4
7
|
|
|
5
8
|
return ({
|
|
6
9
|
isSsr = true,
|
|
@@ -8,21 +11,22 @@ export const useGetServiceHref = () => {
|
|
|
8
11
|
port,
|
|
9
12
|
}: {
|
|
10
13
|
isSsr?: boolean
|
|
11
|
-
name
|
|
14
|
+
name: string
|
|
12
15
|
port?: number
|
|
13
16
|
}) =>
|
|
14
17
|
getServiceHref({
|
|
15
18
|
host,
|
|
16
19
|
isSsr,
|
|
20
|
+
isTesting,
|
|
17
21
|
name,
|
|
18
22
|
port,
|
|
19
23
|
stagingHost: runtimeConfig.public.vio.stagingHost,
|
|
20
|
-
})
|
|
24
|
+
})
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
export const useHost = () => {
|
|
24
|
-
const
|
|
25
|
-
const host = getHost(event)
|
|
27
|
+
export const useHost = ({ event }: { event?: H3Event } = {}) => {
|
|
28
|
+
const { siteUrlTyped: siteUrl } = useSiteUrl()
|
|
29
|
+
const host = event ? getHost(event) : siteUrl.host
|
|
26
30
|
|
|
27
31
|
if (!host) throw new Error('Host is not given!')
|
|
28
32
|
|
package/server/utils/testing.ts
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
import type { H3Event } from 'h3'
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
3
|
+
export const useIsTesting = ({
|
|
4
|
+
isCookieEnabled = true,
|
|
5
|
+
}:
|
|
6
|
+
| {
|
|
7
|
+
isCookieEnabled?: boolean
|
|
8
|
+
}
|
|
9
|
+
| undefined = {}) => {
|
|
10
|
+
const event = useEvent()
|
|
11
|
+
const runtimeConfig = useRuntimeConfig()
|
|
5
12
|
|
|
13
|
+
return getIsTesting({ event, isCookieEnabled, runtimeConfig })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getIsTesting = ({
|
|
17
|
+
event,
|
|
18
|
+
isCookieEnabled,
|
|
19
|
+
runtimeConfig,
|
|
20
|
+
}: {
|
|
21
|
+
event?: H3Event
|
|
22
|
+
isCookieEnabled?: boolean
|
|
23
|
+
runtimeConfig: ReturnType<typeof useRuntimeConfig>
|
|
24
|
+
}) => {
|
|
25
|
+
const isTestingByRuntimeConfig = runtimeConfig.public.vio.isTesting
|
|
6
26
|
if (isTestingByRuntimeConfig) return true
|
|
7
27
|
|
|
8
|
-
if (event) {
|
|
28
|
+
if (isCookieEnabled && event) {
|
|
9
29
|
const isTestingByCookie = !!getCookie(event, TESTING_COOKIE_NAME)
|
|
10
|
-
|
|
11
30
|
if (isTestingByCookie) return true
|
|
12
31
|
}
|
|
13
32
|
}
|
|
@@ -3,6 +3,7 @@ import type { H3Event } from 'h3'
|
|
|
3
3
|
import { computed, reactive } from 'vue'
|
|
4
4
|
import type { Ref } from 'vue'
|
|
5
5
|
|
|
6
|
+
import { SITE_URL_TYPED } from '../../node/static'
|
|
6
7
|
import type { ApiData, BackendError } from '../types/api'
|
|
7
8
|
|
|
8
9
|
export const getApiDataDefault = (): ApiData =>
|
|
@@ -87,25 +88,38 @@ export const getHost = (event: H3Event) => {
|
|
|
87
88
|
export const getServiceHref = ({
|
|
88
89
|
host,
|
|
89
90
|
isSsr = true,
|
|
91
|
+
isTesting,
|
|
90
92
|
name,
|
|
91
93
|
port,
|
|
92
94
|
stagingHost,
|
|
93
95
|
}: {
|
|
94
|
-
host
|
|
96
|
+
host?: string
|
|
95
97
|
isSsr?: boolean
|
|
96
|
-
|
|
98
|
+
isTesting?: boolean
|
|
99
|
+
name: string
|
|
97
100
|
port?: number
|
|
98
101
|
stagingHost?: string
|
|
99
102
|
}) => {
|
|
100
|
-
const nameSubdomain =
|
|
103
|
+
const nameSubdomain =
|
|
104
|
+
name !== VIO_SITE_NAME ? name?.replaceAll('_', '-') : undefined
|
|
101
105
|
const nameSubdomainString = nameSubdomain ? `${nameSubdomain}.` : ''
|
|
102
106
|
const portString = port ? `:${port}` : ''
|
|
103
107
|
|
|
108
|
+
if (isTesting) {
|
|
109
|
+
return `${SITE_URL_TYPED.protocol}//${nameSubdomainString}${SITE_URL_TYPED.host}`
|
|
110
|
+
}
|
|
111
|
+
|
|
104
112
|
if (stagingHost) {
|
|
105
113
|
return `https://${nameSubdomainString}${stagingHost}`
|
|
106
|
-
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (import.meta.server && isSsr) {
|
|
107
117
|
return `http://${name}${portString}`
|
|
108
|
-
} else {
|
|
109
|
-
return `https://${nameSubdomainString}${getRootHost(host)}`
|
|
110
118
|
}
|
|
119
|
+
|
|
120
|
+
if (host) {
|
|
121
|
+
return `https://${nameSubdomainString}${host}`
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
throw new Error('Could not get service href!')
|
|
111
125
|
}
|