From dc05db4459c5520d02a548b5b6335d46bb12070a Mon Sep 17 00:00:00 2001 From: Tsotne Nazarashvili Date: Tue, 25 Jul 2023 12:16:07 +0400 Subject: [PATCH] use Cloudflare Pages (#1035) * use cloudflare pages * remove cf workers setup * Get youtube api key from context env * Update workflows * Lets/try long url withnum 123214bers and stuff one two three (#1069) * set slug-maxlength to 28 and use GITHUB_REF_SLUG_URL * Use dist/client instead of public in previews * api routes for dev server --------- Co-authored-by: lorcan-codes <126797224+lorcan-codes@users.noreply.github.com> --- .github/workflows/netlify-cms.yml | 12 +-- .github/workflows/storybook.yml | 9 ++- .github/workflows/website.yml | 33 ++++---- workspaces/cms-data/src/announcements.ts | 8 +- workspaces/cms-data/src/categories.ts | 4 +- workspaces/cms-data/src/events.ts | 4 +- workspaces/cms-data/src/getSharedData.ts | 6 +- workspaces/cms-data/src/pages.ts | 10 +-- workspaces/cms-data/src/posts.ts | 8 +- workspaces/cms-data/src/roadmap.ts | 12 +-- workspaces/cms-data/src/seo/index.ts | 32 ++++---- workspaces/cms-data/src/settings/alert.ts | 4 +- .../cms-data/src/settings/blog-posts.ts | 4 +- workspaces/cms-data/src/settings/main-menu.ts | 4 +- workspaces/cms-data/src/settings/roadmap.ts | 4 +- workspaces/cms-data/src/topics.ts | 4 +- workspaces/cms-data/src/tutorials.tsx | 9 +-- workspaces/cms-data/src/wallets.ts | 4 +- workspaces/cms-utils/src/index.ts | 20 ++--- workspaces/netlify-cms-auth/package.json | 2 +- .../index.ts => functions/[[route]].ts} | 47 +++++------ workspaces/website/package.json | 10 +-- workspaces/website/src/api/index.ts | 5 +- workspaces/website/src/blocks/Block.tsx | 2 +- .../dataBlocks/BlockWallets/BlockWallets.tsx | 2 +- workspaces/website/src/dev-server/index.ts | 7 +- .../announcements/@slug/index.page.server.tsx | 2 +- .../pages/announcements/index.page.server.tsx | 2 +- .../pages/live-preview/index.page.server.ts | 6 +- .../website/src/pages/pages.page.server.tsx | 2 +- .../@category/@slug/index.page.server.tsx | 6 +- .../posts/@category/index.page.server.ts | 4 +- .../src/pages/posts/index.page.server.ts | 4 +- .../preview/pages/@id/index.page.server.tsx | 2 +- .../preview/posts/@id/index.page.server.ts | 2 +- .../pages/roadmap/@slug/index.page.server.tsx | 6 +- .../src/pages/roadmap/index.page.server.tsx | 6 +- .../tutorials/video/@id/index.page.server.tsx | 4 +- .../src/renderer/PageContextProvider.tsx | 2 +- workspaces/website/src/renderer/helpers.tsx | 2 +- workspaces/website/src/renderer/types.ts | 2 +- workspaces/website/src/types.d.ts | 5 +- .../website/src/worker/static-assets.ts | 64 --------------- workspaces/website/tsconfig.json | 2 +- workspaces/website/vite-dev-server.config.ts | 3 - workspaces/website/vite-worker.config.ts | 30 ------- workspaces/website/wrangler.toml | 12 --- yarn.lock | 80 ++++++++++--------- 48 files changed, 203 insertions(+), 311 deletions(-) rename workspaces/website/{src/worker/index.ts => functions/[[route]].ts} (50%) delete mode 100644 workspaces/website/src/worker/static-assets.ts delete mode 100644 workspaces/website/vite-worker.config.ts delete mode 100644 workspaces/website/wrangler.toml diff --git a/.github/workflows/netlify-cms.yml b/.github/workflows/netlify-cms.yml index df9a9a01c7..2af2fd17e5 100644 --- a/.github/workflows/netlify-cms.yml +++ b/.github/workflows/netlify-cms.yml @@ -6,7 +6,9 @@ on: jobs: build-and-deploy: name: Build and Deploy - environment: "netlify-cms" + environment: + name: Netlify CMS ${{ github.ref_name }} + url: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-netlify-cms.pages.dev permissions: contents: read deployments: write @@ -40,15 +42,15 @@ jobs: - name: Inject slug/short variables uses: rlespinasse/github-slug-action@v4 with: - slug-maxlength: 40 + slug-maxlength: 28 - name: Build Netlify CMS run: yarn workspace @starknet-io/netlify-cms build env: - VITE_LIVE_PREVIEW_URL: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev + VITE_LIVE_PREVIEW_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev VITE_GIT_BRANCH_NAME: ${{ github.ref_name }} - VITE_API_BASE_URL: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev/api - VITE_DATA_URL: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev/data + VITE_API_BASE_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev/api + VITE_DATA_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev/data - name: Deploy Netlify CMS uses: cloudflare/pages-action@1 diff --git a/.github/workflows/storybook.yml b/.github/workflows/storybook.yml index df883bfff6..802cc3fbb0 100644 --- a/.github/workflows/storybook.yml +++ b/.github/workflows/storybook.yml @@ -6,7 +6,9 @@ on: jobs: build-and-deploy: name: Build and Deploy - environment: "storybook" + environment: + name: Storybook ${{ github.ref_name }} + url: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-storybook.pages.dev permissions: contents: read deployments: write @@ -37,6 +39,11 @@ jobs: - name: Install dependencies run: yarn + - name: Inject slug/short variables + uses: rlespinasse/github-slug-action@v4 + with: + slug-maxlength: 28 + - name: Build storybook run: yarn workspace @starknet-io/storybook build-storybook diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 600b9da25f..80c2e3421e 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -8,7 +8,7 @@ jobs: name: Build and Deploy environment: name: Starknet Website ${{ github.ref_name }} - url: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev + url: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev runs-on: ubuntu-22.04 steps: - name: Checkout @@ -48,31 +48,26 @@ jobs: - name: Inject slug/short variables uses: rlespinasse/github-slug-action@v4 with: - slug-maxlength: 40 - - - name: Create Env - run: echo -e "\n[env.${{ env.GITHUB_REF_SLUG }}]\n" >> workspaces/website/wrangler.toml - - - name: Create secrets.json - run: echo '{"YOUTUBE_API_KEY":"${{ secrets.YOUTUBE_API_KEY }}"}' > workspaces/website/secrets.json - - - name: Upload secrets - run: yarn workspace @starknet-io/website exec wrangler secret:bulk secrets.json --env ${{ env.GITHUB_REF_SLUG }} - env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + slug-maxlength: 28 - name: Build project run: yarn workspace @starknet-io/website build env: - VITE_SITE_URL: https://starknet-website-${{ env.GITHUB_REF_SLUG }}.yukilabs.workers.dev + VITE_SITE_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev VITE_ALGOLIA_INDEX: ${{ github.ref_name == 'production' && 'production' || 'dev' }} VITE_ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} VITE_ALGOLIA_SEARCH_API_KEY: ${{ secrets.ALGOLIA_SEARCH_API_KEY }} VITE_CF_STREAM_URL: ${{ secrets.CF_STREAM_URL }} - name: Publish - run: yarn workspace @starknet-io/website exec wrangler publish --env ${{ env.GITHUB_REF_SLUG }} - env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + uses: cloudflare/pages-action@v1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: starknet-website + directory: dist/client + workingDirectory: workspaces/website + wranglerVersion: '3' + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref_name }} + diff --git a/workspaces/cms-data/src/announcements.ts b/workspaces/cms-data/src/announcements.ts index a1d5fb91d2..562cce94f4 100644 --- a/workspaces/cms-data/src/announcements.ts +++ b/workspaces/cms-data/src/announcements.ts @@ -18,12 +18,12 @@ export interface AnnouncementsPost extends Meta, AnnouncementDetails { export async function getAnnouncementDetails( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON(`data/announcements-details/${value}`, event) + (value) => async () => getJSON(`data/announcements-details/${value}`, context) ) ); } catch (cause) { @@ -33,12 +33,12 @@ export async function getAnnouncementDetails( export async function getAnnouncementsPostBySlug( locale: string, slug: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON(`data/announcements/${value}/${slug}`, event) + (value) => async () => getJSON(`data/announcements/${value}/${slug}`, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/categories.ts b/workspaces/cms-data/src/categories.ts index 289561ea03..b4bbf40e41 100644 --- a/workspaces/cms-data/src/categories.ts +++ b/workspaces/cms-data/src/categories.ts @@ -9,12 +9,12 @@ export interface Category { export async function getCategories( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/categories/" + value, event) + (value) => async () => getJSON("data/categories/" + value, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/events.ts b/workspaces/cms-data/src/events.ts index e741aabe1d..bba2ad4257 100644 --- a/workspaces/cms-data/src/events.ts +++ b/workspaces/cms-data/src/events.ts @@ -25,12 +25,12 @@ export interface Event { export async function getEvents( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/events/" + value, event) + (value) => async () => getJSON("data/events/" + value, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/getSharedData.ts b/workspaces/cms-data/src/getSharedData.ts index 2641b5104a..6eba5e7e47 100644 --- a/workspaces/cms-data/src/getSharedData.ts +++ b/workspaces/cms-data/src/getSharedData.ts @@ -11,11 +11,11 @@ type SharedData = { } export async function getSharedData( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"], + context: EventContext<{}, any, Record>, ): Promise { return getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/shared-data/" + value, event) + (value) => async () => getJSON("data/shared-data/" + value, context) ) ); - } \ No newline at end of file + } diff --git a/workspaces/cms-data/src/pages.ts b/workspaces/cms-data/src/pages.ts index f0b7dbd862..84589deb64 100644 --- a/workspaces/cms-data/src/pages.ts +++ b/workspaces/cms-data/src/pages.ts @@ -203,7 +203,7 @@ export interface Page extends Meta { const getPageWithRandomizedData = (data: Page): Page => { const randomizedData = {...data} randomizedData.blocks?.forEach((block: TopLevelBlock) => { - + if (block.type === 'link_list' && block.randomize) { //@ts-expect-error block.blocks = getShuffledArray(block.blocks || []); @@ -218,13 +218,13 @@ const getPageWithRandomizedData = (data: Page): Page => { export async function getPageBySlug( slug: string, locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { const data = await getFirst( ...[locale, defaultLocale].map( (value) => async () => - getJSON("data/pages/" + value + "/" + slug, event) + getJSON("data/pages/" + value + "/" + slug, context) ) ); @@ -239,12 +239,12 @@ export async function getPageBySlug( export async function getPageById( id: string, locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/pages/" + value + "/" + id, event) + (value) => async () => getJSON("data/pages/" + value + "/" + id, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/posts.ts b/workspaces/cms-data/src/posts.ts index 3e51d08577..ab3ad93eef 100644 --- a/workspaces/cms-data/src/posts.ts +++ b/workspaces/cms-data/src/posts.ts @@ -30,13 +30,13 @@ export interface Post extends Meta { export async function getPostBySlug( slug: string, locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( (value) => async () => - getJSON("data/posts/" + value + "/" + slug, event) + getJSON("data/posts/" + value + "/" + slug, context) ), async () => { const client = algoliasearch( @@ -70,12 +70,12 @@ export async function getPostBySlug( export async function getPostById( id: string | string[] | undefined, locale: string | string[], - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/posts/" + value + "/" + id, event) + (value) => async () => getJSON("data/posts/" + value + "/" + id, context) ), async () => { const client = algoliasearch( diff --git a/workspaces/cms-data/src/roadmap.ts b/workspaces/cms-data/src/roadmap.ts index e4132e6c15..1b0fd4a622 100644 --- a/workspaces/cms-data/src/roadmap.ts +++ b/workspaces/cms-data/src/roadmap.ts @@ -25,12 +25,12 @@ export interface RoadmapVersion extends Meta { export async function getRoadmapDetails( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON(`data/roadmap-details/${value}`, event) + (value) => async () => getJSON(`data/roadmap-details/${value}`, context) ) ); } catch (cause) { @@ -43,12 +43,12 @@ export async function getRoadmapDetails( export async function getRoadmapPostBySlug( locale: string, slug: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON(`data/roadmap-posts/${value}/${slug}`, event) + (value) => async () => getJSON(`data/roadmap-posts/${value}/${slug}`, context) ) ); } catch (cause) { @@ -60,12 +60,12 @@ export async function getRoadmapPostBySlug( export async function getRoadmapVersions( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/roadmap-versions/" + value, event) + (value) => async () => getJSON("data/roadmap-versions/" + value, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/seo/index.ts b/workspaces/cms-data/src/seo/index.ts index 57f47518e7..e845c71d01 100644 --- a/workspaces/cms-data/src/seo/index.ts +++ b/workspaces/cms-data/src/seo/index.ts @@ -34,22 +34,22 @@ export interface SEOTexts { async function getSEO( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"], + context: EventContext<{}, any, Record>, page: T ): Promise { return getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/seo/" + page + "/" + value, event) + (value) => async () => getJSON("data/seo/" + page + "/" + value, context) ) ); } export async function getTutorialsSEO( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { - return await getSEO(locale, event, "tutorials"); + return await getSEO(locale, context, "tutorials"); } catch (cause) { throw new Error("getTutorialsSEO failed!", { cause, @@ -59,10 +59,10 @@ export async function getTutorialsSEO( export async function getEventsSEO( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { - return await getSEO(locale, event, "events"); + return await getSEO(locale, context, "events"); } catch (cause) { throw new Error("getEventsSEO failed!", { cause, @@ -72,10 +72,10 @@ export async function getEventsSEO( export async function getJobsSEO( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { - return await getSEO(locale, event, "jobs"); + return await getSEO(locale, context, "jobs"); } catch (cause) { throw new Error("getJobsSEO failed!", { cause, @@ -85,10 +85,10 @@ export async function getJobsSEO( export async function getFooterSEO( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { - return await getSEO(locale, event, "footer"); + return await getSEO(locale, context, "footer"); } catch (cause) { throw new Error("getFooterSEO failed!", { cause, @@ -98,10 +98,10 @@ export async function getFooterSEO( export async function getHomeSEO( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { - return await getSEO(locale, event, "home"); + return await getSEO(locale, context, "home"); } catch (cause) { throw new Error("getHomeSEO failed!", { cause, @@ -111,10 +111,10 @@ export async function getHomeSEO( export async function getSearchSEO( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { - return await getSEO(locale, event, "search"); + return await getSEO(locale, context, "search"); } catch (cause) { throw new Error("getSearchSEO failed!", { cause, @@ -124,10 +124,10 @@ export async function getSearchSEO( export async function getLanguageCenterSEO( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { - return await getSEO(locale, event, "language"); + return await getSEO(locale, context, "language"); } catch (cause) { throw new Error("getLanguageCenterSEO failed!", { cause, diff --git a/workspaces/cms-data/src/settings/alert.ts b/workspaces/cms-data/src/settings/alert.ts index fe75c5cc1a..37996a90a7 100644 --- a/workspaces/cms-data/src/settings/alert.ts +++ b/workspaces/cms-data/src/settings/alert.ts @@ -12,12 +12,12 @@ export interface Alert { export async function getAlerts( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/alert/" + value, event) + (value) => async () => getJSON("data/alert/" + value, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/settings/blog-posts.ts b/workspaces/cms-data/src/settings/blog-posts.ts index d3928e5c66..c798a3a155 100644 --- a/workspaces/cms-data/src/settings/blog-posts.ts +++ b/workspaces/cms-data/src/settings/blog-posts.ts @@ -7,12 +7,12 @@ export interface BlogPosts { export async function getBlogPosts( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/blog-posts/" + value, event) + (value) => async () => getJSON("data/blog-posts/" + value, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/settings/main-menu.ts b/workspaces/cms-data/src/settings/main-menu.ts index 31db9bb513..a9f5b158da 100644 --- a/workspaces/cms-data/src/settings/main-menu.ts +++ b/workspaces/cms-data/src/settings/main-menu.ts @@ -39,12 +39,12 @@ export interface BlockItem extends LinkData { export async function getMainMenu( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/main-menu/" + value, event) + (value) => async () => getJSON("data/main-menu/" + value, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/settings/roadmap.ts b/workspaces/cms-data/src/settings/roadmap.ts index 628240b38d..1338e73b8c 100644 --- a/workspaces/cms-data/src/settings/roadmap.ts +++ b/workspaces/cms-data/src/settings/roadmap.ts @@ -10,11 +10,11 @@ export interface Roadmap { readonly roadmap_post_ps?: string; } -export async function getRoadmapSettings(locale: string, event: null | WorkerGlobalScopeEventMap["fetch"]): Promise { +export async function getRoadmapSettings(locale: string, context: EventContext<{}, any, Record>): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/roadmap/" + value, event) + (value) => async () => getJSON("data/roadmap/" + value, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/topics.ts b/workspaces/cms-data/src/topics.ts index c20a8bcc12..7af13343b2 100644 --- a/workspaces/cms-data/src/topics.ts +++ b/workspaces/cms-data/src/topics.ts @@ -8,12 +8,12 @@ export interface Topic { export async function getTopics( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { return await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/topics/" + value, event) + (value) => async () => getJSON("data/topics/" + value, context) ) ); } catch (cause) { diff --git a/workspaces/cms-data/src/tutorials.tsx b/workspaces/cms-data/src/tutorials.tsx index fc64e9a81c..dd2844dafb 100644 --- a/workspaces/cms-data/src/tutorials.tsx +++ b/workspaces/cms-data/src/tutorials.tsx @@ -7,11 +7,6 @@ type Author = { readonly author_link?: string; } -type Author = { - readonly author?: string; - readonly author_link?: string; -} - export type Tutorial = { readonly id?: string; readonly type: "youtube" | "blog" | "github"; @@ -30,12 +25,12 @@ export type Tutorial = { export const getTutorialById = async ( id: string, locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ) => { return getFirst( ...[locale, defaultLocale].map( (value) => async () => - getJSON("data/tutorials/" + value + "/" + id, event) + getJSON("data/tutorials/" + value + "/" + id, context) ), // async () => { // const client = algoliasearch( diff --git a/workspaces/cms-data/src/wallets.ts b/workspaces/cms-data/src/wallets.ts index 39b048757f..ef9ab0e146 100644 --- a/workspaces/cms-data/src/wallets.ts +++ b/workspaces/cms-data/src/wallets.ts @@ -17,12 +17,12 @@ export interface Wallet { export async function getWallets( locale: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { try { const wallets = await getFirst( ...[locale, defaultLocale].map( - (value) => async () => getJSON("data/wallets/" + value, event) + (value) => async () => getJSON("data/wallets/" + value, context) ) ); diff --git a/workspaces/cms-utils/src/index.ts b/workspaces/cms-utils/src/index.ts index 7e8bd87d84..ff87adee9f 100644 --- a/workspaces/cms-utils/src/index.ts +++ b/workspaces/cms-utils/src/index.ts @@ -1,5 +1,4 @@ import type { DefaultLogFields } from "simple-git"; -import { getAssetFromKV } from "@cloudflare/kv-asset-handler"; export function youtubeVideoIdFromURL(url: string): string | undefined | void { try { @@ -61,20 +60,13 @@ export async function getFirst(...fns: Array<() => Promise>): Promise { export async function getJSON( src: string, - event: null | WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ): Promise { - if (import.meta.env.SSR || event) { - if (globalThis.__STATIC_CONTENT) { - const res = await getAssetFromKV({ - request: new Request( - new URL("/" + src + ".json", "http://localhost:3000") - ), - waitUntil(promise) { - event?.waitUntil(promise); - }, - }); + if (import.meta.env.SSR || context) { + if (context) { + const res = await context.env.ASSETS.fetch(new URL("/" + src + ".json", "http://localhost:3000")) - return res.json(); + return res.json() } else if (import.meta.env.DEV) { const fs = await import("node:fs/promises"); const path = await import("node:path"); @@ -112,4 +104,4 @@ export function getShuffledArray(_array: readonly T[]) { } return array; -} \ No newline at end of file +} diff --git a/workspaces/netlify-cms-auth/package.json b/workspaces/netlify-cms-auth/package.json index 37270894f1..886a4a82be 100644 --- a/workspaces/netlify-cms-auth/package.json +++ b/workspaces/netlify-cms-auth/package.json @@ -12,7 +12,7 @@ "@cloudflare/workers-types": "^4.20230518.0", "typescript": "^5.0.4", "vitest": "^0.31.4", - "wrangler": "^3.1.0" + "wrangler": "^3.3.0" }, "dependencies": { "@octokit/oauth-app": "^4.2.1" diff --git a/workspaces/website/src/worker/index.ts b/workspaces/website/functions/[[route]].ts similarity index 50% rename from workspaces/website/src/worker/index.ts rename to workspaces/website/functions/[[route]].ts index c825752370..3f66669501 100644 --- a/workspaces/website/src/worker/index.ts +++ b/workspaces/website/functions/[[route]].ts @@ -1,52 +1,50 @@ -import { apiRouter, corsify, preflight } from "../api"; -import { handleStaticAssets } from "./static-assets"; +import { apiRouter, corsify, preflight } from "../src/api"; import { renderPage } from "vite-plugin-ssr/server"; import { IRequest, Router } from "itty-router"; -import * as redirects from "../../redirects.json"; +import * as redirects from "../redirects.json"; const router = Router(); -router.all("/api/*", apiRouter.handle); +router.all("/api/*", (req, context) => apiRouter.handle(req, context.env)); redirects.items.forEach(({ source, destination }) => { router.get( source, - (req: IRequest, event: WorkerGlobalScopeEventMap["fetch"]) => { + (req: IRequest, context: EventContext<{}, any, Record>) => { let src = destination for (const [key, value] of Object.entries(req.params)) { src = src.replace(new RegExp(`:${key}\\+?`), value) } - return Response.redirect(new URL(src, event.request.url), 301); + return Response.redirect(new URL(src, req.url), 301); } ); }); async function ittyAssetshandler( req: IRequest, - event: WorkerGlobalScopeEventMap["fetch"] + context: EventContext<{}, any, Record> ) { - return await handleStaticAssets(event); + return context.env.ASSETS.fetch(req); } -router.get("/*.txt", ittyAssetshandler); router.get("/*.png", ittyAssetshandler); router.get("/*.svg", ittyAssetshandler); router.get("/*.ico", ittyAssetshandler); router.get("/assets/*", ittyAssetshandler); router.all("/data/*", preflight); -router.get("/data/*", async (req, event) => { - return corsify(await handleStaticAssets(event)); +router.get("/data/*", async (req, context: EventContext<{}, any, Record>) => { + return corsify(await context.env.ASSETS.fetch(req)); }); -router.all("*", async (req, event: WorkerGlobalScopeEventMap["fetch"]) => { - const userAgent = event.request.headers.get("User-Agent")!; +router.all("*", async (req, context: EventContext<{}, any, Record>) => { + const userAgent = req.headers.get("User-Agent")!; const pageContextInit = { - event, - urlOriginal: event.request.url, + context, + urlOriginal: req.url, fetch, userAgent, }; @@ -55,7 +53,7 @@ router.all("*", async (req, event: WorkerGlobalScopeEventMap["fetch"]) => { if (pageContext.redirectTo) { return Response.redirect( - new URL(pageContext.redirectTo, event.request.url), + new URL(pageContext.redirectTo, req.url), 301 ); } else if (pageContext.httpResponse != null) { @@ -65,14 +63,13 @@ router.all("*", async (req, event: WorkerGlobalScopeEventMap["fetch"]) => { }); } - return await handleStaticAssets(event); + return context.env.ASSETS.fetch(req); }); -addEventListener("fetch", async (event: WorkerGlobalScopeEventMap["fetch"]) => { - event.respondWith( - router.handle(event.request, event).catch((err) => { - console.error(err); - return new Response("Internal Error", { status: 500 }); - }) - ); -}); + +export const onRequest: PagesFunction<{}> = async (context) => { + return router.handle(context.request, context).catch((err) => { + console.error(err); + return new Response("Internal Error", { status: 500 }); + }) +} diff --git a/workspaces/website/package.json b/workspaces/website/package.json index 4dcd66fa7d..94a1854c06 100644 --- a/workspaces/website/package.json +++ b/workspaces/website/package.json @@ -4,11 +4,9 @@ "version": "0.0.0", "scripts": { "dev": "vite-node ./src/dev-server -c vite-dev-server.config.ts", - "build": "yarn build-ssr && yarn build-worker", - "build-worker": "vite build -c vite-worker.config.ts", - "build-ssr": "vite build -c vite.config.ts", - "preview": "wrangler dev", - "preview-remote": "wrangler dev --remote" + "build": "vite build -c vite.config.ts", + "preview": "yarn wrangler pages dev --compatibility-date=2023-07-17 --port 3000 dist/client", + "preview-remote": "yarn wrangler pages dev --compatibility-date=2023-07-17 --port 3000 dist/client --remote" }, "dependencies": { "@cloudflare/kv-asset-handler": "^0.3.0", @@ -30,6 +28,6 @@ "vite-node": "0.30.1", "vite-plugin-ssr": "^0.4.131", "vite-tsconfig-paths": "^4.2.0", - "wrangler": "^3.1.0" + "wrangler": "^3.3.0" } } diff --git a/workspaces/website/src/api/index.ts b/workspaces/website/src/api/index.ts index 6f021a1c03..158f10b4fa 100644 --- a/workspaces/website/src/api/index.ts +++ b/workspaces/website/src/api/index.ts @@ -11,7 +11,7 @@ apiRouter.all("*", preflight); apiRouter.get( "/youtube", - async (req, event: WorkerGlobalScopeEventMap["fetch"]) => { + async (req, env: PAGES_VARS) => { if (typeof req.query.id !== "string") { return corsify(error(422, { message: "Invalid id provided!" })); } @@ -19,7 +19,8 @@ apiRouter.get( const query = new URLSearchParams(); query.set("version", "v3"); - query.set("key", YOUTUBE_API_KEY); + // TODO fix env for cf pages + query.set("key", env.YOUTUBE_API_KEY); query.set("id", req.query.id as string); query.set("part", "snippet"); query.append("part", "contentDetails"); diff --git a/workspaces/website/src/blocks/Block.tsx b/workspaces/website/src/blocks/Block.tsx index 8089301b41..b49c68eeb0 100644 --- a/workspaces/website/src/blocks/Block.tsx +++ b/workspaces/website/src/blocks/Block.tsx @@ -140,7 +140,7 @@ export function Block({ block, locale }: Props): JSX.Element | null { } else if (block.type === "home_hero") { const pageContext = usePageContext(); const homeSEO = useAsync(["getBlockExplorers", locale], () => - getHomeSEO(locale, pageContext.event) + getHomeSEO(locale, pageContext.context) ); return ; diff --git a/workspaces/website/src/blocks/dataBlocks/BlockWallets/BlockWallets.tsx b/workspaces/website/src/blocks/dataBlocks/BlockWallets/BlockWallets.tsx index 8205526c37..1504f79ffc 100644 --- a/workspaces/website/src/blocks/dataBlocks/BlockWallets/BlockWallets.tsx +++ b/workspaces/website/src/blocks/dataBlocks/BlockWallets/BlockWallets.tsx @@ -13,7 +13,7 @@ export default function BlockWallets({ params: { locale }, }: Props): JSX.Element { const pageContext = usePageContext(); - const wallets = useAsync(['getWallets', locale], () => getWallets(locale, pageContext.event)); + const wallets = useAsync(['getWallets', locale], () => getWallets(locale, pageContext.context)); return ( diff --git a/workspaces/website/src/dev-server/index.ts b/workspaces/website/src/dev-server/index.ts index c31fdddba3..d72fe459fc 100644 --- a/workspaces/website/src/dev-server/index.ts +++ b/workspaces/website/src/dev-server/index.ts @@ -4,8 +4,12 @@ import { renderPage } from "vite-plugin-ssr/server"; import { createServer } from "vite"; import fetch from "node-fetch"; import compression from "compression"; +import * as dotenv from "dotenv"; import { apiRouter } from "../api"; +const dotenvFiles = [".env.local", ".env"]; +dotenvFiles.forEach((path) => dotenv.config({ path })); + const app = express(); // We don't need gzip compression for dev. We use compression just to show @@ -25,7 +29,8 @@ app.all(/\/api(.*)/, async (req, res, next) => { method: req.method, body: req.body, headers: Object.entries(req.headers) as HeadersInit, - }) + }), + process.env ); if (httpResponse != null) { diff --git a/workspaces/website/src/pages/announcements/@slug/index.page.server.tsx b/workspaces/website/src/pages/announcements/@slug/index.page.server.tsx index 41dca1bef1..cdf4bcabd7 100644 --- a/workspaces/website/src/pages/announcements/@slug/index.page.server.tsx +++ b/workspaces/website/src/pages/announcements/@slug/index.page.server.tsx @@ -6,7 +6,7 @@ import { AnnouncementPostProps } from "./(components)/AnnouncementPost"; export async function onBeforeRender(pageContext: PageContextServer) { const defaultPageContext = await getDefaultPageContext(pageContext); const { locale } = defaultPageContext; - const announcementsPost = await getAnnouncementsPostBySlug(locale, pageContext.routeParams.slug, pageContext.event); + const announcementsPost = await getAnnouncementsPostBySlug(locale, pageContext.routeParams.slug, pageContext.context); const pageProps: AnnouncementPostProps = { announcementsPost, diff --git a/workspaces/website/src/pages/announcements/index.page.server.tsx b/workspaces/website/src/pages/announcements/index.page.server.tsx index a4567b7f38..60798421ea 100644 --- a/workspaces/website/src/pages/announcements/index.page.server.tsx +++ b/workspaces/website/src/pages/announcements/index.page.server.tsx @@ -6,7 +6,7 @@ import { PageContextServer } from "src/renderer/types"; export async function onBeforeRender(pageContext: PageContextServer) { const defaultPageContext = await getDefaultPageContext(pageContext); const { locale } = defaultPageContext; - const announcements = await getAnnouncementDetails(locale, pageContext.event); + const announcements = await getAnnouncementDetails(locale, pageContext.context); const pageProps: AnnouncementsPageProps = { announcements, diff --git a/workspaces/website/src/pages/live-preview/index.page.server.ts b/workspaces/website/src/pages/live-preview/index.page.server.ts index 0b1b735788..7703466f8a 100644 --- a/workspaces/website/src/pages/live-preview/index.page.server.ts +++ b/workspaces/website/src/pages/live-preview/index.page.server.ts @@ -10,9 +10,9 @@ export async function onBeforeRender(pageContext: PageContextServer) { const { locale } = defaultPageContext; const pageProps: Props = { - categories: await getCategories(locale, pageContext.event), - topics: await getTopics(locale, pageContext.event), - roadmapVersions: await getRoadmapVersions(locale, pageContext.event) + categories: await getCategories(locale, pageContext.context), + topics: await getTopics(locale, pageContext.context), + roadmapVersions: await getRoadmapVersions(locale, pageContext.context) }; return { diff --git a/workspaces/website/src/pages/pages.page.server.tsx b/workspaces/website/src/pages/pages.page.server.tsx index af93bbeff0..cac605417a 100644 --- a/workspaces/website/src/pages/pages.page.server.tsx +++ b/workspaces/website/src/pages/pages.page.server.tsx @@ -7,7 +7,7 @@ import { Props } from "src/pages/PagePage"; export async function onBeforeRender(pageContext: PageContextServer) { const locale = pageContext.locale ?? defaultLocale; const slug = pageContext.routeParams["*"] || "home"; - const data = await getPageBySlug(slug, locale, pageContext.event); + const data = await getPageBySlug(slug, locale, pageContext.context); return { pageContext: { diff --git a/workspaces/website/src/pages/posts/@category/@slug/index.page.server.tsx b/workspaces/website/src/pages/posts/@category/@slug/index.page.server.tsx index 5a04e4345c..6273690165 100644 --- a/workspaces/website/src/pages/posts/@category/@slug/index.page.server.tsx +++ b/workspaces/website/src/pages/posts/@category/@slug/index.page.server.tsx @@ -12,13 +12,13 @@ export async function onBeforeRender(pageContext: PageContextServer) { const post = await getPostBySlug( pageContext.routeParams.slug, locale, - pageContext.event + pageContext.context ) const pageProps: Props = { post , - categories: await getCategories(locale, pageContext.event), - topics: await getTopics(locale, pageContext.event), + categories: await getCategories(locale, pageContext.context), + topics: await getTopics(locale, pageContext.context), params: { locale, slug: pageContext.routeParams!.slug!, diff --git a/workspaces/website/src/pages/posts/@category/index.page.server.ts b/workspaces/website/src/pages/posts/@category/index.page.server.ts index 047b484562..c50ed2155c 100644 --- a/workspaces/website/src/pages/posts/@category/index.page.server.ts +++ b/workspaces/website/src/pages/posts/@category/index.page.server.ts @@ -9,8 +9,8 @@ export async function onBeforeRender(pageContext: PageContextServer) { const { locale } = defaultPageContext; const pageProps: Props = { - categories: await getCategories(locale, pageContext.event), - topics: await getTopics(locale, pageContext.event), + categories: await getCategories(locale, pageContext.context), + topics: await getTopics(locale, pageContext.context), env: { ALGOLIA_INDEX: import.meta.env.VITE_ALGOLIA_INDEX!, ALGOLIA_APP_ID: import.meta.env.VITE_ALGOLIA_APP_ID!, diff --git a/workspaces/website/src/pages/posts/index.page.server.ts b/workspaces/website/src/pages/posts/index.page.server.ts index 24e994d042..617fd5d1eb 100644 --- a/workspaces/website/src/pages/posts/index.page.server.ts +++ b/workspaces/website/src/pages/posts/index.page.server.ts @@ -9,8 +9,8 @@ export async function onBeforeRender(pageContext: PageContextServer) { const { locale } = defaultPageContext; const pageProps: Props = { - categories: await getCategories(locale, pageContext.event), - topics: await getTopics(locale, pageContext.event), + categories: await getCategories(locale, pageContext.context), + topics: await getTopics(locale, pageContext.context), env: { ALGOLIA_INDEX: import.meta.env.VITE_ALGOLIA_INDEX!, ALGOLIA_APP_ID: import.meta.env.VITE_ALGOLIA_APP_ID!, diff --git a/workspaces/website/src/pages/preview/pages/@id/index.page.server.tsx b/workspaces/website/src/pages/preview/pages/@id/index.page.server.tsx index bfdb113da6..9181b679bf 100644 --- a/workspaces/website/src/pages/preview/pages/@id/index.page.server.tsx +++ b/workspaces/website/src/pages/preview/pages/@id/index.page.server.tsx @@ -5,7 +5,7 @@ export async function render(pageContext: PageContextServer) { const data = await getPageById( pageContext.routeParams.id, pageContext.locale, - pageContext.event + pageContext.context ); return { diff --git a/workspaces/website/src/pages/preview/posts/@id/index.page.server.ts b/workspaces/website/src/pages/preview/posts/@id/index.page.server.ts index 827c6317c6..42151e4aa2 100644 --- a/workspaces/website/src/pages/preview/posts/@id/index.page.server.ts +++ b/workspaces/website/src/pages/preview/posts/@id/index.page.server.ts @@ -5,7 +5,7 @@ export async function render(pageContext: PageContextServer) { const data = await getPostById( pageContext.routeParams.id, pageContext.locale, - pageContext.event + pageContext.context ); return { diff --git a/workspaces/website/src/pages/roadmap/@slug/index.page.server.tsx b/workspaces/website/src/pages/roadmap/@slug/index.page.server.tsx index ca54f6b533..79fdc1ac93 100644 --- a/workspaces/website/src/pages/roadmap/@slug/index.page.server.tsx +++ b/workspaces/website/src/pages/roadmap/@slug/index.page.server.tsx @@ -10,9 +10,9 @@ import { getRoadmapSettings } from "@starknet-io/cms-data/src/settings/roadmap"; export async function onBeforeRender(pageContext: PageContextServer) { const defaultPageContext = await getDefaultPageContext(pageContext); const { locale } = defaultPageContext; - const roadmapPost = await getRoadmapPostBySlug(locale, pageContext.routeParams.slug, pageContext.event); - const roadmapVersions = await getRoadmapVersions(locale, pageContext.event); - const roadmapSettings = await getRoadmapSettings(locale, pageContext.event) + const roadmapPost = await getRoadmapPostBySlug(locale, pageContext.routeParams.slug, pageContext.context); + const roadmapVersions = await getRoadmapVersions(locale, pageContext.context); + const roadmapSettings = await getRoadmapSettings(locale, pageContext.context) console.log('roadmapVersions', roadmapVersions) diff --git a/workspaces/website/src/pages/roadmap/index.page.server.tsx b/workspaces/website/src/pages/roadmap/index.page.server.tsx index 5108f28c31..01b9819c3f 100644 --- a/workspaces/website/src/pages/roadmap/index.page.server.tsx +++ b/workspaces/website/src/pages/roadmap/index.page.server.tsx @@ -10,9 +10,9 @@ import { getRoadmapSettings } from "@starknet-io/cms-data/src/settings/roadmap"; export async function onBeforeRender(pageContext: PageContextServer) { const defaultPageContext = await getDefaultPageContext(pageContext); const { locale } = defaultPageContext; - const roadmapPosts = await getRoadmapDetails(locale, pageContext.event); - const roadmapVersions = await getRoadmapVersions(locale, pageContext.event); - const roadmapSettings = await getRoadmapSettings(locale, pageContext.event); + const roadmapPosts = await getRoadmapDetails(locale, pageContext.context); + const roadmapVersions = await getRoadmapVersions(locale, pageContext.context); + const roadmapSettings = await getRoadmapSettings(locale, pageContext.context); const pageProps: RoadmapPageProps = { roadmapPosts, diff --git a/workspaces/website/src/pages/tutorials/video/@id/index.page.server.tsx b/workspaces/website/src/pages/tutorials/video/@id/index.page.server.tsx index 1ab4f52ab6..8be2e4c293 100644 --- a/workspaces/website/src/pages/tutorials/video/@id/index.page.server.tsx +++ b/workspaces/website/src/pages/tutorials/video/@id/index.page.server.tsx @@ -7,13 +7,13 @@ import { getTutorialById } from "@starknet-io/cms-data/src/tutorials"; export async function onBeforeRender(pageContext: PageContextServer) { const defaultPageContext = await getDefaultPageContext(pageContext); const { locale } = defaultPageContext; - const tutorial = await getTutorialById(pageContext.routeParams.id, locale, pageContext.event); + const tutorial = await getTutorialById(pageContext.routeParams.id, locale, pageContext.context); const pageProps: Props = { tutorial, params: { locale, - id: pageContext.routeParams.id ?? '' + id: pageContext.routeParams.id ?? '' } }; diff --git a/workspaces/website/src/renderer/PageContextProvider.tsx b/workspaces/website/src/renderer/PageContextProvider.tsx index feb4af2b72..0f7e48430e 100644 --- a/workspaces/website/src/renderer/PageContextProvider.tsx +++ b/workspaces/website/src/renderer/PageContextProvider.tsx @@ -11,7 +11,7 @@ export function PageContextProvider({ children: React.ReactNode; }) { if (!import.meta.env.SSR) { - pageContext.event = null; + pageContext.context = null; } return {children}; diff --git a/workspaces/website/src/renderer/helpers.tsx b/workspaces/website/src/renderer/helpers.tsx index 200ef24df9..ef537c86a2 100644 --- a/workspaces/website/src/renderer/helpers.tsx +++ b/workspaces/website/src/renderer/helpers.tsx @@ -14,7 +14,7 @@ export async function getDefaultPageContext( pageContext: PageContextServer ): Promise> { const locale = pageContext.locale ?? defaultLocale; - const sharedData = await getSharedData(locale, pageContext.event) + const sharedData = await getSharedData(locale, pageContext.context) return { locale, diff --git a/workspaces/website/src/renderer/types.ts b/workspaces/website/src/renderer/types.ts index 9c917cda2c..309c39dec9 100644 --- a/workspaces/website/src/renderer/types.ts +++ b/workspaces/website/src/renderer/types.ts @@ -31,7 +31,7 @@ export type PageContextCustom = { }; documentProps?: DocumentProps; locale: string; - event: null | WorkerGlobalScopeEventMap["fetch"]; + context: EventContext<{}, any, Record>; userAgent: string; redirectTo?: string; mainMenu: MainMenu; diff --git a/workspaces/website/src/types.d.ts b/workspaces/website/src/types.d.ts index ee0800b53e..15c3035524 100644 --- a/workspaces/website/src/types.d.ts +++ b/workspaces/website/src/types.d.ts @@ -5,5 +5,6 @@ declare interface LocaleParams { declare interface LocaleProps { readonly params: LocaleParams; } - -declare var YOUTUBE_API_KEY: string; +declare interface PAGES_VARS { + readonly YOUTUBE_API_KEY: string; +} diff --git a/workspaces/website/src/worker/static-assets.ts b/workspaces/website/src/worker/static-assets.ts deleted file mode 100644 index 77b1425d46..0000000000 --- a/workspaces/website/src/worker/static-assets.ts +++ /dev/null @@ -1,64 +0,0 @@ -// ******************************************** -// This code was provided by Cloudflare Workers -// ******************************************** - -import { getAssetFromKV } from "@cloudflare/kv-asset-handler"; - -/** - * The DEBUG flag will do two things that help during development: - * 1. we will skip caching on the edge, which makes it easier to - * debug. - * 2. we will return an error message on exception in your Response rather - * than the default 404.html page. - */ -const DEBUG = false; - -export async function handleStaticAssets( - event: WorkerGlobalScopeEventMap["fetch"] -) { - let options: any = {}; - - /** - * You can add custom logic to how we fetch your assets - * by configuring the function `mapRequestToAsset` - */ - // options.mapRequestToAsset = handlePrefix(/^\/docs/) - - try { - if (DEBUG) { - // customize caching - options.cacheControl = { - bypassCache: true, - }; - } - const page = await getAssetFromKV(event, options); - - // allow headers to be altered - const response = new Response(page.body, page); - - response.headers.set("X-XSS-Protection", "1; mode=block"); - response.headers.set("X-Content-Type-Options", "nosniff"); - response.headers.set("X-Frame-Options", "DENY"); - response.headers.set("Referrer-Policy", "unsafe-url"); - response.headers.set("Feature-Policy", "none"); - - return response; - } catch (e: any) { - // if an error is thrown try to serve the asset at 404.html - if (!DEBUG) { - try { - let notFoundResponse = await getAssetFromKV(event, { - mapRequestToAsset: (req) => - new Request(`${new URL(req.url).origin}/404.html`, req), - }); - - return new Response(notFoundResponse.body, { - ...notFoundResponse, - status: 404, - }); - } catch (e) {} - } - - return new Response(e.message || e.toString(), { status: 500 }); - } -} diff --git a/workspaces/website/tsconfig.json b/workspaces/website/tsconfig.json index 526fb37237..8eab8b2dd3 100644 --- a/workspaces/website/tsconfig.json +++ b/workspaces/website/tsconfig.json @@ -11,7 +11,7 @@ "resolveJsonModule": true, "baseUrl": "." }, - "include": ["src/**/*", "*.json"], + "include": ["functions/**/*","src/**/*", "*.json"], "references": [ { "path": "../cms-utils" }, { "path": "../cms-config" }, diff --git a/workspaces/website/vite-dev-server.config.ts b/workspaces/website/vite-dev-server.config.ts index 5d2146de0d..5b02852267 100644 --- a/workspaces/website/vite-dev-server.config.ts +++ b/workspaces/website/vite-dev-server.config.ts @@ -6,7 +6,4 @@ export default { resolve: { conditions: ['import', 'module', 'node', 'default'] }, - define: { - 'YOUTUBE_API_KEY': JSON.stringify(process.env.YOUTUBE_API_KEY) - } } as UserConfig diff --git a/workspaces/website/vite-worker.config.ts b/workspaces/website/vite-worker.config.ts deleted file mode 100644 index 7ed41a60bb..0000000000 --- a/workspaces/website/vite-worker.config.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { UserConfig } from "vite"; -import path from "path"; -import tsconfigPaths from "vite-tsconfig-paths"; - -export default { - plugins: [tsconfigPaths()], - build: { - outDir: 'dist/worker', - emptyOutDir: true, - lib: { - entry: path.resolve(__dirname, "src/worker/index.ts"), - name: "worker", - fileName: "worker", - }, - rollupOptions: { - // make sure to externalize deps that shouldn't be bundled - // into your library - external: [ - // src/worker/index.ts - "vite-plugin-ssr/server", - - // src/worker/static-assets.ts - "@cloudflare/kv-asset-handler", - - // src/api/index.ts - "itty-router", - ], - }, - }, -} as UserConfig; diff --git a/workspaces/website/wrangler.toml b/workspaces/website/wrangler.toml deleted file mode 100644 index 0595ec9647..0000000000 --- a/workspaces/website/wrangler.toml +++ /dev/null @@ -1,12 +0,0 @@ -main="./dist/worker/worker.mjs" -name = "starknet-website" -compatibility_flags = ["streams_enable_constructors"] -compatibility_date = "2021-09-29" -workers_dev = true -node_compat = true - -[site] -bucket = "./dist/client" - -[dev] -port = 3000 diff --git a/yarn.lock b/yarn.lock index 0179cfebb9..2089aaf541 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2993,37 +2993,37 @@ __metadata: languageName: node linkType: hard -"@cloudflare/workerd-darwin-64@npm:1.20230518.0": - version: 1.20230518.0 - resolution: "@cloudflare/workerd-darwin-64@npm:1.20230518.0" +"@cloudflare/workerd-darwin-64@npm:1.20230717.0": + version: 1.20230717.0 + resolution: "@cloudflare/workerd-darwin-64@npm:1.20230717.0" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@cloudflare/workerd-darwin-arm64@npm:1.20230518.0": - version: 1.20230518.0 - resolution: "@cloudflare/workerd-darwin-arm64@npm:1.20230518.0" +"@cloudflare/workerd-darwin-arm64@npm:1.20230717.0": + version: 1.20230717.0 + resolution: "@cloudflare/workerd-darwin-arm64@npm:1.20230717.0" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@cloudflare/workerd-linux-64@npm:1.20230518.0": - version: 1.20230518.0 - resolution: "@cloudflare/workerd-linux-64@npm:1.20230518.0" +"@cloudflare/workerd-linux-64@npm:1.20230717.0": + version: 1.20230717.0 + resolution: "@cloudflare/workerd-linux-64@npm:1.20230717.0" conditions: os=linux & cpu=x64 languageName: node linkType: hard -"@cloudflare/workerd-linux-arm64@npm:1.20230518.0": - version: 1.20230518.0 - resolution: "@cloudflare/workerd-linux-arm64@npm:1.20230518.0" +"@cloudflare/workerd-linux-arm64@npm:1.20230717.0": + version: 1.20230717.0 + resolution: "@cloudflare/workerd-linux-arm64@npm:1.20230717.0" conditions: os=linux & cpu=arm64 languageName: node linkType: hard -"@cloudflare/workerd-windows-64@npm:1.20230518.0": - version: 1.20230518.0 - resolution: "@cloudflare/workerd-windows-64@npm:1.20230518.0" +"@cloudflare/workerd-windows-64@npm:1.20230717.0": + version: 1.20230717.0 + resolution: "@cloudflare/workerd-windows-64@npm:1.20230717.0" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -4621,7 +4621,7 @@ __metadata: "@octokit/oauth-app": ^4.2.1 typescript: ^5.0.4 vitest: ^0.31.4 - wrangler: ^3.1.0 + wrangler: ^3.3.0 languageName: unknown linkType: soft @@ -4744,7 +4744,7 @@ __metadata: vite-node: 0.30.1 vite-plugin-ssr: ^0.4.131 vite-tsconfig-paths: ^4.2.0 - wrangler: ^3.1.0 + wrangler: ^3.3.0 languageName: unknown linkType: soft @@ -13490,9 +13490,9 @@ __metadata: languageName: node linkType: hard -"miniflare@npm:^3.0.0": - version: 3.0.1 - resolution: "miniflare@npm:3.0.1" +"miniflare@npm:3.20230717.0": + version: 3.20230717.0 + resolution: "miniflare@npm:3.20230717.0" dependencies: acorn: ^8.8.0 acorn-walk: ^8.2.0 @@ -13502,14 +13502,15 @@ __metadata: glob-to-regexp: ^0.4.1 http-cache-semantics: ^4.1.0 kleur: ^4.1.5 + set-cookie-parser: ^2.6.0 source-map-support: 0.5.21 stoppable: ^1.1.0 undici: ^5.13.0 - workerd: ^1.20230512.0 + workerd: 1.20230717.0 ws: ^8.11.0 youch: ^3.2.2 zod: ^3.20.6 - checksum: ba9fbfb15d90aa1bfd406d6cfb649ad9720064a03f2d7b0df1d9e1a5308d3f8481ee2ff135e8c4ce19d9bef4c75c917a6f418539dbbf2fbc705764fb1e29fb53 + checksum: d37c9171bbc97a5723ef58cf35fad9649e70e19192411861648534f44a4bbe88695bb8d9d445f5b14609a7f140c7cd8486c4abf446886e2335f67ed03c8b1e3f languageName: node linkType: hard @@ -17387,6 +17388,13 @@ __metadata: languageName: node linkType: hard +"set-cookie-parser@npm:^2.6.0": + version: 2.6.0 + resolution: "set-cookie-parser@npm:2.6.0" + checksum: bf11ebc594c53d84588f1b4c04f1b8ce14e0498b1c011b3d76b5c6d5aac481bbc3f7c5260ec4ce99bdc1d9aed19f9fc315e73166a36ca74d0f12349a73f6bdc9 + languageName: node + linkType: hard + "set-harmonic-interval@npm:^1.0.1": version: 1.0.1 resolution: "set-harmonic-interval@npm:1.0.1" @@ -19874,15 +19882,15 @@ __metadata: languageName: node linkType: hard -"workerd@npm:^1.20230512.0": - version: 1.20230518.0 - resolution: "workerd@npm:1.20230518.0" +"workerd@npm:1.20230717.0": + version: 1.20230717.0 + resolution: "workerd@npm:1.20230717.0" dependencies: - "@cloudflare/workerd-darwin-64": 1.20230518.0 - "@cloudflare/workerd-darwin-arm64": 1.20230518.0 - "@cloudflare/workerd-linux-64": 1.20230518.0 - "@cloudflare/workerd-linux-arm64": 1.20230518.0 - "@cloudflare/workerd-windows-64": 1.20230518.0 + "@cloudflare/workerd-darwin-64": 1.20230717.0 + "@cloudflare/workerd-darwin-arm64": 1.20230717.0 + "@cloudflare/workerd-linux-64": 1.20230717.0 + "@cloudflare/workerd-linux-arm64": 1.20230717.0 + "@cloudflare/workerd-windows-64": 1.20230717.0 dependenciesMeta: "@cloudflare/workerd-darwin-64": optional: true @@ -19896,13 +19904,13 @@ __metadata: optional: true bin: workerd: bin/workerd - checksum: 1d1b45d478695e5d4ecab98d6b200a9bc23e66cd72f2707cef843a44bcfd0817ff9cb50413bd7929de8b1f13147828e3c21157351d61ec7f9c1b55dceee1e046 + checksum: fd96df04675c406b5c897fd6ce4a25ace1ea6fbb89aa49d45cf7ef632041a780890b01d8830b62c8afbfc9c2b0aebb654d7ab46e43d17aeeef00832546e34aaa languageName: node linkType: hard -"wrangler@npm:^3.1.0": - version: 3.1.0 - resolution: "wrangler@npm:3.1.0" +"wrangler@npm:^3.3.0": + version: 3.3.0 + resolution: "wrangler@npm:3.3.0" dependencies: "@cloudflare/kv-asset-handler": ^0.2.0 "@esbuild-plugins/node-globals-polyfill": ^0.1.1 @@ -19911,7 +19919,7 @@ __metadata: chokidar: ^3.5.3 esbuild: 0.16.3 fsevents: ~2.3.2 - miniflare: ^3.0.0 + miniflare: 3.20230717.0 nanoid: ^3.3.3 path-to-regexp: ^6.2.0 selfsigned: ^2.0.1 @@ -19923,7 +19931,7 @@ __metadata: bin: wrangler: bin/wrangler.js wrangler2: bin/wrangler.js - checksum: 03ff3905cb32db214f5338ac514b306c22f3684f402405d12abf96d0672d94082a5fd9249b67bfa86710824b8643914987173ca1443a30340530ae6824a7c68b + checksum: 27b157ffab9913fe7fffc4609babb9041f7017a6e2d55ab785153808758557067af64240af14cec8e955dbf423812e20f770cea7f281f6de576b5311704bae45 languageName: node linkType: hard