From f67c2ee791108fe8baa983fde926429486d38692 Mon Sep 17 00:00:00 2001 From: jiyuujin Date: Thu, 11 Jul 2024 12:54:06 +0900 Subject: [PATCH] add feature flag for datasource (speaker, sponsor) --- apps/web/.env.example | 2 ++ apps/web/app/server/api/speakers.get.ts | 20 +++++++++++++++----- apps/web/app/server/api/sponsors.get.ts | 20 +++++++++++++++----- apps/web/nuxt.config.ts | 3 +++ 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/apps/web/.env.example b/apps/web/.env.example index ab03a3d2..697fa5df 100644 --- a/apps/web/.env.example +++ b/apps/web/.env.example @@ -4,6 +4,8 @@ NUXT_NEWT_FORM_UID= NUXT_RECAPTCHA_WEBSITE_KEY= SUPABASE_URL= SUPABASE_KEY= +SPEAKER_DATASOURCE= # local or supabase +SPONSOR_DATASOURCE= # local or supabase AVAILABLE_APPLY_SPONSOR= ENABLE_INVITE_STAFF= ENABLE_OPERATE_ADMIN= diff --git a/apps/web/app/server/api/speakers.get.ts b/apps/web/app/server/api/speakers.get.ts index 5643309b..777a9293 100644 --- a/apps/web/app/server/api/speakers.get.ts +++ b/apps/web/app/server/api/speakers.get.ts @@ -1,15 +1,23 @@ -// import db from '../db' +import db from '../db' import { defineEventHandler } from 'h3' import type { Speaker, SpeakerInfo } from '@vuejs-jp/model' import { serverSupabaseClient } from '#supabase/server' import { Database } from '~/types/supabase' export default defineEventHandler(async (event) => { - // const response = await db.speaker.getList() - // const speakers = response.default as Speaker[] + const config = useRuntimeConfig() + let speakers: Speaker[] = [] - const client = await serverSupabaseClient(event) - const { data: speakers } = await client.from('speakers').select() as { data: Speaker[] } + if (config.public.speakerDatasource === 'local') { + const response = await db.speaker.getList() + speakers = response.default as Speaker[] + } + + if (config.public.speakerDatasource === 'supabase') { + const client = await serverSupabaseClient(event) + const { data: _speakers } = await client.from('speakers').select() as { data: Speaker[] } + speakers = _speakers + } const sessionSpeakers: SpeakerInfo = { type: 'session', @@ -25,6 +33,7 @@ export default defineEventHandler(async (event) => { return a.display_order - b.display_order }), } + const lightningTalkSpeakers: SpeakerInfo = { type: 'lightning-talk', title: 'Lightning talk', @@ -39,6 +48,7 @@ export default defineEventHandler(async (event) => { return a.display_order - b.display_order }), } + const sponsorSessionSpeakers: SpeakerInfo = { type: 'sponsor-session', title: 'Sponsor session', diff --git a/apps/web/app/server/api/sponsors.get.ts b/apps/web/app/server/api/sponsors.get.ts index 9d225885..44a73aa4 100644 --- a/apps/web/app/server/api/sponsors.get.ts +++ b/apps/web/app/server/api/sponsors.get.ts @@ -1,15 +1,23 @@ -// import db from '../db' +import db from '../db' import { defineEventHandler } from 'h3' import type { Sponsor, SponsorInfo } from '@vuejs-jp/model' import { serverSupabaseClient } from '#supabase/server' import { Database } from '~/types/supabase' export default defineEventHandler(async (event) => { - // const response = await db.sponsor.getList() - // const sponsors = response.default as Sponsor[] + const config = useRuntimeConfig() + let sponsors: Sponsor[] = [] - const client = await serverSupabaseClient(event) - const { data: sponsors } = await client.from('sponsors').select() as { data: Sponsor[] } + if (config.public.sponsorDatasource === 'local') { + const response = await db.sponsor.getList() + sponsors = response.default as Sponsor[] + } + + if (config.public.sponsorDatasource === 'supabase') { + const client = await serverSupabaseClient(event) + const { data: _sponsors } = await client.from('sponsors').select() as { data: Sponsor[] } + sponsors = _sponsors + } const platinumSponsors: SponsorInfo = { type: 'platinum', @@ -160,6 +168,7 @@ export default defineEventHandler(async (event) => { return a.display_order - b.display_order }), } + const toolSponsors: SponsorInfo = { type: 'option', title: 'tool', @@ -174,6 +183,7 @@ export default defineEventHandler(async (event) => { return a.display_order - b.display_order }), } + return { platinumSponsors, goldSponsors, diff --git a/apps/web/nuxt.config.ts b/apps/web/nuxt.config.ts index fc574e02..331c9933 100644 --- a/apps/web/nuxt.config.ts +++ b/apps/web/nuxt.config.ts @@ -135,6 +135,9 @@ export default defineNuxtConfig({ supabaseUrl: process.env.SUPABASE_URL, supabaseKey: process.env.SUPABASE_KEY, serviceKey: process.env.SERVICE_KEY, + // datasource + speakerDatasource : process.env.SPEAKER_DATASOURCE, // local or supabase + sponsorDatasource : process.env.SPONSOR_DATASOURCE, // local or supabase // feature availableApplySponsor: process.env.AVAILABLE_APPLY_SPONSOR, enableInviteStaff: process.env.ENABLE_INVITE_STAFF,