The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
made localhost work without env vars
Steven Tey8c3f6e4029ec
diff --git a/app/ui/home/globe.tsx b/app/ui/home/globe.tsxindex 5311c6cf4a..ee4904411c 100644--- a/app/ui/home/globe.tsx+++ b/app/ui/home/globe.tsx@@ -1,19 +1,18 @@import GlobeClient from "./globe-client";export default async function Globe() {- const response = await fetch(- `https://api.us-east.tinybird.co/v0/pipes/coordinates.json`,- {- headers: {- Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,- },- next: {- revalidate: 43200, // every 12 hours- },- },- )- .then((res) => res.json())- .then((res) => res.data);+ const response = process.env.TINYBIRD_API_KEY+ ? await fetch(`https://api.us-east.tinybird.co/v0/pipes/coordinates.json`, {+ headers: {+ Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,+ },+ next: {+ revalidate: 43200, // every 12 hours+ },+ })+ .then((res) => res.json())+ .then((res) => res.data)+ : [];const markers = response.map(({ latitude, longitude }, idx) => {return {diff --git a/app/ui/home/stats.tsx b/app/ui/home/stats.tsxindex b472cc4d3a..0e6ed2ca35 100644--- a/app/ui/home/stats.tsx+++ b/app/ui/home/stats.tsx@@ -6,16 +6,18 @@ export default async function Stats() {const [domains, shortlinks, clicks] = await Promise.all([getTotalVerifiedDomains(),getTotalLinks(),- fetch(`https://api.us-east.tinybird.co/v0/pipes/all_clicks.json`, {- headers: {- Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,- },- next: {- revalidate: 300,- },- })- .then((res) => res.json())- .then((res) => res.data[0]["count(timestamp)"]),+ process.env.TINYBIRD_API_KEY+ ? fetch(`https://api.us-east.tinybird.co/v0/pipes/all_clicks.json`, {+ headers: {+ Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,+ },+ next: {+ revalidate: 300,+ },+ })+ .then((res) => res.json())+ .then((res) => res.data[0]["count(timestamp)"])+ : 5000000,]);return (diff --git a/emails/index.ts b/emails/index.tsindex 050f3786be..54bf56b5f6 100644--- a/emails/index.ts+++ b/emails/index.ts@@ -2,7 +2,9 @@ import { nanoid } from "#/lib/utils";import { ReactElement, JSXElementConstructor } from "react";import { Resend } from "resend";-export const resend = new Resend(process.env.RESEND_API_KEY);+export const resend = process.env.RESEND_API_KEY+ ? new Resend(process.env.RESEND_API_KEY)+ : null;export const sendEmail = async ({email,@@ -17,6 +19,12 @@ export const sendEmail = async ({marketing?: boolean;test?: boolean;}) => {+ if (!resend) {+ console.log(+ "Resend is not configured. You need to add a RESEND_API_KEY in your .env file for emails to work.",+ );+ return Promise.resolve();+ }return resend.emails.send({from: marketing? "Steven from Dub <[email protected]>"diff --git a/lib/edge-config.ts b/lib/edge-config.tsindex 7e7c303bfd..274ab9409c 100644--- a/lib/edge-config.ts+++ b/lib/edge-config.ts@@ -44,6 +44,18 @@ export const isBlacklistedEmail = async (email: string) => {};export const isReservedKey = async (key: string) => {+ if (!process.env.EDGE_CONFIG) {+ // If EDGE_CONFIG is not set, these are the default reserved keys+ return [+ "blog",+ "help",+ "pricing",+ "changelog",+ "metatags",+ "terms",+ "privacy",+ ];+ }let reservedKey;try {reservedKey = await get("reserved");diff --git a/lib/stats.ts b/lib/stats.tsindex ec0d2a921f..8bbc7e1bc1 100644--- a/lib/stats.ts+++ b/lib/stats.ts@@ -117,14 +117,14 @@ export const getStats = async ({endpoint: string;interval?: string | null;}) => {- if (!process.env.TINYBIRD_API_KEY) {- return null;- }-- // Note: we're doing decodeURIComponent here because that's how we store it in MySQL and Tinybird+ // Note: we're using decodeURIComponent in this function because that's how we store it in MySQL and Tinybird- if (!VALID_TINYBIRD_ENDPOINTS.has(endpoint)) {- return null;+ if (+ !conn ||+ !process.env.TINYBIRD_API_KEY ||+ !VALID_TINYBIRD_ENDPOINTS.has(endpoint)+ ) {+ return [];}// get all-time clicks count if: