Merge branch 'dev'
This commit is contained in:
commit
d7fce2eac0
@ -2,6 +2,8 @@ NUXT_PUBLIC_PREVIEW_MODE=true
|
||||
NUXT_PUBLIC_SLUG_DEFAULT_LENGTH=5
|
||||
NUXT_SITE_TOKEN=SinkCool
|
||||
NUXT_REDIRECT_STATUS_CODE=308
|
||||
NUXT_LINK_CACHE_TTL=60
|
||||
NUXT_REDIRECT_WITH_QUERY=false
|
||||
NUXT_HOME_URL="https://sink.cool"
|
||||
NUXT_CF_ACCOUNT_ID=123456
|
||||
NUXT_CF_API_TOKEN=CloudflareAPIToken
|
||||
|
||||
@ -10,14 +10,14 @@ const route = useRoute()
|
||||
@update:model-value="navigateTo"
|
||||
>
|
||||
<TabsList>
|
||||
<TabsTrigger value="/dashboard">
|
||||
Analysis
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="/dashboard/links"
|
||||
>
|
||||
Links
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="/dashboard/analysis">
|
||||
Analysis
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<slot name="left" />
|
||||
|
||||
@ -14,6 +14,14 @@ Sets the default length of the generated SLUG.
|
||||
|
||||
Redirects default to use HTTP 301 status code, you can set it to `302`/`307`/`308`.
|
||||
|
||||
## `NUXT_LINK_CACHE_TTL`
|
||||
|
||||
Cache links can speed up access, but setting them too long may result in slow changes taking effect. The default value is 60 seconds.
|
||||
|
||||
## `NUXT_REDIRECT_WITH_QUERY`
|
||||
|
||||
URL parameters are not carried during link redirection by default and it is not recommended to enable this feature.
|
||||
|
||||
## `NUXT_HOME_URL`
|
||||
|
||||
The default Sink homepage is the introduction page, you can replace it with your own website.
|
||||
|
||||
@ -21,6 +21,9 @@ export default defineNuxtConfig({
|
||||
'/dashboard/**': {
|
||||
ssr: false,
|
||||
},
|
||||
'/dashboard': {
|
||||
redirect: '/dashboard/links',
|
||||
},
|
||||
},
|
||||
|
||||
hub: {
|
||||
@ -49,6 +52,8 @@ export default defineNuxtConfig({
|
||||
runtimeConfig: {
|
||||
siteToken: 'SinkCool',
|
||||
redirectStatusCode: '301',
|
||||
linkCacheTtl: 60,
|
||||
redirectWithQuery: false,
|
||||
homeURL: '',
|
||||
cfAccountId: '',
|
||||
cfApiToken: '',
|
||||
@ -62,4 +67,4 @@ export default defineNuxtConfig({
|
||||
},
|
||||
|
||||
compatibilityDate: '2024-07-08',
|
||||
})
|
||||
})
|
||||
|
||||
@ -12,6 +12,7 @@ export default eventHandler(async (event) => {
|
||||
statusText: 'Link already exists',
|
||||
})
|
||||
}
|
||||
|
||||
else {
|
||||
const expiration = getExpiration(event, link.expiration)
|
||||
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import type { z } from 'zod'
|
||||
import { parsePath } from 'ufo'
|
||||
import { parsePath, withQuery } from 'ufo'
|
||||
import type { LinkSchema } from '@/schemas/link'
|
||||
|
||||
export default eventHandler(async (event) => {
|
||||
const { pathname: slug } = parsePath(event.path.slice(1)) // remove leading slash
|
||||
const { slugRegex, reserveSlug } = useAppConfig(event)
|
||||
const { homeURL } = useRuntimeConfig(event)
|
||||
const { homeURL, linkCacheTtl, redirectWithQuery } = useRuntimeConfig(event)
|
||||
const { cloudflare } = event.context
|
||||
|
||||
if (event.path === '/' && homeURL)
|
||||
@ -13,7 +13,7 @@ export default eventHandler(async (event) => {
|
||||
|
||||
if (slug && !reserveSlug.includes(slug) && slugRegex.test(slug) && cloudflare) {
|
||||
const { KV } = cloudflare.env
|
||||
const link: z.infer<typeof LinkSchema> | null = await KV.get(`link:${slug}`, { type: 'json' })
|
||||
const link: z.infer<typeof LinkSchema> | null = await KV.get(`link:${slug}`, { type: 'json', cacheTtl: linkCacheTtl })
|
||||
if (link) {
|
||||
event.context.link = link
|
||||
try {
|
||||
@ -22,7 +22,8 @@ export default eventHandler(async (event) => {
|
||||
catch (error) {
|
||||
console.error('Failed write access log:', error)
|
||||
}
|
||||
return sendRedirect(event, link.url, +useRuntimeConfig(event).redirectStatusCode)
|
||||
const target = redirectWithQuery ? withQuery(link.url, getQuery(event)) : link.url
|
||||
return sendRedirect(event, target, +useRuntimeConfig(event).redirectStatusCode)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user