uniswap-interface-uncensored/functions
Charles Bachmeier 13f57d8d73
feat: block dynamic link previews for blocked collections (#7344)
* feat: block link previews for blocked collections

* update collection test

* single invalid

* move blocklist to its own const file

* rename file to blocklist
2023-09-19 11:07:07 -07:00
..
api/image feat: block dynamic link previews for blocked collections (#7344) 2023-09-19 11:07:07 -07:00
components feat: add CodeCov to cloud tests (#7154) 2023-08-17 11:30:56 -04:00
nfts test: update cloud test snapshots (#7311) 2023-09-14 12:27:58 -05:00
tokens test: update cloud test snapshots (#7311) 2023-09-14 12:27:58 -05:00
utils fix: add assets to public folder (#7153) 2023-08-17 16:15:17 -04:00
[[index]].ts fix: remove description from custom rich link previews (#7142) 2023-08-11 18:53:48 -04:00
babel.config.js feat: wrangler infra and test environment (#6797) 2023-07-07 11:41:09 -04:00
client.ts feat: cloudflare worker to inject meta tags (#6901) 2023-07-18 12:35:29 -04:00
constants.ts feat: custom colors for rich link previews (#7141) 2023-08-11 12:27:46 -04:00
default.test.ts fix: remove description from custom rich link previews (#7142) 2023-08-11 18:53:48 -04:00
jest.config.json test: fix cloud tests (#7280) 2023-09-08 10:53:22 -07:00
README.md test: fix cloud tests (#7280) 2023-09-08 10:53:22 -07:00
setupAfterEnv.ts fix: remove flakey tests from cloud functions and overall deflake (#7156) 2023-08-14 16:50:49 -04:00
tsconfig.json feat: dynamically generated images for rich link previews (#6902) 2023-08-10 15:29:37 -04:00
types.d.ts feat: dynamically generated images for rich link previews (#6902) 2023-08-10 15:29:37 -04:00

Cloudflare Cloud Functions

Purpose

These functions utilize Cloudflare Functions to dynamically inject meta tags server side for richer link sharing capabilities.

Functions

Currently, there are 2 types of cloudflare functions developed

  • Meta Data Injectors - Workers that inject Open Graph standardized meta tags into the header of specific webpages.
    • Currently we support this functionaltiy for three separate webpages: NFT Assets, NFT Collections, and Token Detail Pages
    • These functions query data from GraphQL and then formats them into HTML meta tags to be injected
  • Dynamically Generated Images - Utilizes Vercel's Open Graph Image Generation Library to create custom thumbnails for specific webpages
    • Currently supports NFT Assets, NFT Collections, and Token Detail Pages
    • These functions query data from GraphQL, and utilize Satori to convert HTML into a png image response which is then returned when the api is called.
    • Can be found in the api/image folder.

Testing

Testing is done utilizing a custom jest environment as well as Cloudflare's local tester: wrangler. Wrangler enables testing locally by running a proxy to wrap localhost. Tests run against a proxy server, so you'll need to start it before running tests:

  • Manually run yarn start:cloud to setup wrangler on localhost:3000
  • Run unit tests with yarn test:cloud

Deployment

Functions will be deployed to Cloudlfare where they will be ran automatically when the appropriate route is hit.

Miscellaneous

  • Caching: In order to speed up webpage requests, repeated GraphQL queries will be saved and pulled using Cloudflare's Cache API.

Scripts

  • yarn start:cloud (NODE_OPTIONS=--dns-result-order=ipv4first PORT=3001 npx wrangler pages dev --node-compat --proxy=3001 --port=3000 -- yarn start), script to start local wrangler environment

    • npx wrangler pages dev: this basis of this command which starts a local instance of wrangler to test cloud functions
    • --node-compat: wrangler option that enables compatibility with Node.js modules
    • --proxy:3001: telling the proxy to listen on port 3001
    • --port=3000: telling wrangler to run our proxy on port 3000
    • NODE_OPTIONS=--dns-result-order=ipv4first: wrangler still serves to IPv4 which isn't compatible with Node 18 which default resolves to IPv6 so we need to specify to serve to IPv4
    • PORT-3001 --yarn start: runs default yarn start on port 3001
  • yarn test:cloud (NODE_OPTIONS=--experimental-vm-modules yarn jest functions --watch --config=functions/jest.config.json), script to test cloud functions with jest

    • NODE_OPTIONS=--experimental-vm-modules: support for ES Modules and Web Assembly
    • --config=functions/jest.config.json: specifying which config file to use

    Additional Documents