vercel-edge-deploy-test

This commit is contained in:
Untone 2024-08-12 14:42:31 +03:00
parent e6e19d74cd
commit a186dc4d3f
5 changed files with 29 additions and 19 deletions

View File

@ -8,7 +8,7 @@ import sassDts from 'vite-plugin-sass-dts'
const isVercel = Boolean(process?.env.VERCEL) const isVercel = Boolean(process?.env.VERCEL)
const isNetlify = Boolean(process?.env.NETLIFY) const isNetlify = Boolean(process?.env.NETLIFY)
const isBun = Boolean(process.env.BUN) const isBun = Boolean(process.env.BUN)
const runtime = isNetlify ? 'netlify' : isVercel ? 'vercel' : isBun ? 'bun' : 'node' const runtime = isNetlify ? 'netlify' : isVercel ? 'vercel_edge' : isBun ? 'bun' : 'node'
console.info(`[app.config] build for ${runtime}!`) console.info(`[app.config] build for ${runtime}!`)
const polyfillOptions = { const polyfillOptions = {

View File

@ -15,17 +15,13 @@ const fetchAuthorsWithStat = async (offset = 0, order?: string) => {
return await authorsFetcher() return await authorsFetcher()
} }
export const fetchAllAuthors = async () => {
const authorsAllFetcher = loadAuthorsAll()
return await authorsAllFetcher()
}
export const route = { export const route = {
load: async ({ location: { query } }: RouteLoadFuncArgs) => { load: async ({ location: { query } }: RouteLoadFuncArgs) => {
const by = query.by const by = query.by
const isAll = !by || by === 'name' const isAll = !by || by === 'name'
const authorsAllFetcher = loadAuthorsAll()
return { return {
authors: isAll && (await fetchAllAuthors()), authors: isAll && (await authorsAllFetcher()),
authorsByFollowers: await fetchAuthorsWithStat(10, 'followers'), authorsByFollowers: await fetchAuthorsWithStat(10, 'followers'),
authorsByShouts: await fetchAuthorsWithStat(10, 'shouts') authorsByShouts: await fetchAuthorsWithStat(10, 'shouts')
} as AllAuthorsData } as AllAuthorsData
@ -38,13 +34,14 @@ type AllAuthorsData = { authors: Author[]; authorsByFollowers: Author[]; authors
export default function AllAuthorsPage(props: RouteSectionProps<AllAuthorsData>) { export default function AllAuthorsPage(props: RouteSectionProps<AllAuthorsData>) {
const { t } = useLocalize() const { t } = useLocalize()
const { addAuthors } = useAuthors() const { addAuthors, authorsSorted } = useAuthors()
// async load data: from ssr or fetch // async load data: from ssr or fetch
const data = createAsync<AllAuthorsData>(async () => { const data = createAsync<AllAuthorsData>(async () => {
if (props.data) return props.data if (props.data) return props.data
const authorsAllFetcher = loadAuthorsAll()
return { return {
authors: await fetchAllAuthors(), authors: authorsSorted() || await authorsAllFetcher(),
authorsByFollowers: await fetchAuthorsWithStat(10, 'followers'), authorsByFollowers: await fetchAuthorsWithStat(10, 'followers'),
authorsByShouts: await fetchAuthorsWithStat(10, 'shouts') authorsByShouts: await fetchAuthorsWithStat(10, 'shouts')
} as AllAuthorsData } as AllAuthorsData

View File

@ -2,21 +2,27 @@ import { RouteDefinition, RouteSectionProps, createAsync } from '@solidjs/router
import { InboxView } from '~/components/Views/Inbox/Inbox' import { InboxView } from '~/components/Views/Inbox/Inbox'
import { PageLayout } from '~/components/_shared/PageLayout' import { PageLayout } from '~/components/_shared/PageLayout'
import { ShowOnlyOnClient } from '~/components/_shared/ShowOnlyOnClient' import { ShowOnlyOnClient } from '~/components/_shared/ShowOnlyOnClient'
import { useAuthors } from '~/context/authors'
import { useLocalize } from '~/context/localize' import { useLocalize } from '~/context/localize'
import { loadAuthorsAll } from '~/graphql/api/public'
import { Author } from '~/graphql/schema/core.gen' import { Author } from '~/graphql/schema/core.gen'
import { fetchAllAuthors } from '../author/(all-authors)'
export const route = { export const route = {
load: async () => { load: async () => {
const authorsAllFetcher = loadAuthorsAll()
return { return {
authors: await fetchAllAuthors() authors: await authorsAllFetcher()
} }
} }
} satisfies RouteDefinition } satisfies RouteDefinition
export const InboxPage = (props: RouteSectionProps<{ authors: Author[] }>) => { export const InboxPage = (props: RouteSectionProps<{ authors: Author[] }>) => {
const { t } = useLocalize() const { t } = useLocalize()
const authors = createAsync(async () => props.data.authors || (await fetchAllAuthors())) const { authorsSorted } = useAuthors()
const authors = createAsync(async () => {
const authorsAllFetcher = loadAuthorsAll()
return props.data.authors || authorsSorted() || (await authorsAllFetcher())
})
return ( return (
<PageLayout hideFooter={true} title={t('Inbox')}> <PageLayout hideFooter={true} title={t('Inbox')}>

View File

@ -6,14 +6,15 @@ import { ShowOnlyOnClient } from '~/components/_shared/ShowOnlyOnClient'
import { useInbox } from '~/context/inbox' import { useInbox } from '~/context/inbox'
import { useLocalize } from '~/context/localize' import { useLocalize } from '~/context/localize'
import { useSession } from '~/context/session' import { useSession } from '~/context/session'
import { loadAuthorsAll } from '~/graphql/api/public'
import { Chat } from '~/graphql/schema/chat.gen' import { Chat } from '~/graphql/schema/chat.gen'
import { Author } from '~/graphql/schema/core.gen' import { Author } from '~/graphql/schema/core.gen'
import { fetchAllAuthors } from '../author/(all-authors)'
export const route = { export const route = {
load: async () => { load: async () => {
const authorsAllFetcher = loadAuthorsAll()
return { return {
authors: await fetchAllAuthors() authors: await authorsAllFetcher()
} }
} }
} satisfies RouteDefinition } satisfies RouteDefinition
@ -24,7 +25,10 @@ export const ChatPage = (props: RouteSectionProps<{ authors: Author[] }>) => {
const { createChat, chats } = useInbox() const { createChat, chats } = useInbox()
const [chat, setChat] = createSignal<Chat>() const [chat, setChat] = createSignal<Chat>()
const { session } = useSession() const { session } = useSession()
const authors = createAsync(async () => props.data.authors || (await fetchAllAuthors())) const authors = createAsync(async () => {
const authorsAllFetcher = loadAuthorsAll()
return props.data.authors || (await authorsAllFetcher())
})
onMount(async () => { onMount(async () => {
if (params.id.includes('-')) { if (params.id.includes('-')) {

View File

@ -38,14 +38,17 @@ export type TopicPageProps = { articles?: Shout[]; topics: Topic[]; authors?: Au
export default function TopicPage(props: RouteSectionProps<TopicPageProps>) { export default function TopicPage(props: RouteSectionProps<TopicPageProps>) {
const { t } = useLocalize() const { t } = useLocalize()
const { addTopics } = useTopics() const { addTopics, sortedTopics } = useTopics()
const [loadingError, setLoadingError] = createSignal(false) const [loadingError, setLoadingError] = createSignal(false)
const topic = createAsync(async () => { const topic = createAsync(async () => {
try { try {
const ttt: Topic[] = props.data.topics || (await fetchAllTopics()) || [] let ttt: Topic[] = sortedTopics()
addTopics(ttt) if (!ttt) {
console.debug('[route.topic] all topics loaded') ttt = props.data.topics || (await fetchAllTopics()) || []
addTopics(ttt)
console.debug('[route.topic] all topics loaded')
}
const t = ttt.find((x) => x.slug === props.params.slug) const t = ttt.find((x) => x.slug === props.params.slug)
return t return t
} catch (_error) { } catch (_error) {