Skip to content

Commit

Permalink
Merge pull request #358 from roycoprotocol/uday
Browse files Browse the repository at this point in the history
feat(api): server side proxies
  • Loading branch information
githubotoro authored Jan 22, 2025
2 parents bb0d74c + a6e94ac commit 9c4f1dc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import WalletProvider from "@/components/rainbow-modal/context-provider";
import { TurnstileWrapper } from "@/auth";
import { Toaster as ToasterSonner } from "@/components/ui/sonner";
import { UserInfoSetter } from "@/components/user/hooks";
import { RoycoAnalytics } from "./royco-analytics";

/**
* @description Inter Font
Expand Down Expand Up @@ -142,6 +143,10 @@ export default function RootLayout({

<BrowserDetector />

{/* {process.env.NODE_ENV !== "development" && (
<RoycoAnalytics id={process.env.ANALYTICS_ID!} />
)} */}

<Toaster />
</body>
</html>
Expand Down
16 changes: 16 additions & 0 deletions app/royco-analytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client";

import Script from "next/script";

export const RoycoAnalytics = ({ id }: { id: string }) => {
if (typeof window !== "undefined") {
return (
<Script
defer
src={`${window.location.origin}/script.js`}
data-website-id={id}
data-host-url={`${window.location.origin}/api/event`}
/>
);
}
};
1 change: 1 addition & 0 deletions components/constants/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const RPC_API_KEYS: {
421614: process.env.NEXT_PUBLIC_RPC_API_KEY_421614!,
8453: process.env.NEXT_PUBLIC_RPC_API_KEY_8453!,
84532: process.env.NEXT_PUBLIC_RPC_API_KEY_84532!,
146: process.env.NEXT_PUBLIC_RPC_API_KEY_146!,
};

export const OwnershipProofMessage =
Expand Down
14 changes: 7 additions & 7 deletions components/rainbow-modal/modal-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@ export const config = getDefaultConfig({
transports: {
[EthereumMainnet.id]: fallback([
unstable_connector(injected),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_1),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_1!),
http(),
]),
[ArbitrumOne.id]: fallback([
unstable_connector(injected),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_42161),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_42161!),
http(),
]),
[Base.id]: fallback([
unstable_connector(injected),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_8453),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_8453!),
http(),
]),
[Corn.id]: fallback([
unstable_connector(injected),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_21000000),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_21000000!),
http(),
]),
[Plume.id]: fallback([
unstable_connector(injected),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_98865),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_98865!),
http(),
]),
[EthereumSepolia.id]: fallback([
unstable_connector(injected),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_11155111),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_11155111!),
http(),
]),
[Sonic.id]: fallback([
unstable_connector(injected),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_146),
http(process.env.NEXT_PUBLIC_RPC_API_KEY_146!),
http(),
]),
},
Expand Down
8 changes: 8 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ const RateLimits = {
},
};

const logIncomingRequest = (request: NextRequest) => {
console.log("Incoming request:", request.nextUrl.pathname);
};

export async function middleware(request: NextRequest) {
// if (process.env.NODE_ENV === "development") {
// logIncomingRequest(request);
// }

/**
* Current path
*/
Expand Down
3 changes: 2 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const nextConfig = {
fetches: {
fullUrl: true,
},
rewrites: true,
},
// Reverse proxy to Posthog and Royco Analytics
rewrites: async () => {
Expand All @@ -48,7 +49,7 @@ const nextConfig = {
destination: "https://royco-analytics.vercel.app/:path*", // Proxy to Royco Analytics
},
{
source: "/api/rpc/:path*",
source: "/api/rpc/1/:path*",
destination: process.env.RPC_API_KEY_1,
},
{
Expand Down

0 comments on commit 9c4f1dc

Please sign in to comment.