Skip to content

Commit

Permalink
try different way to get user ip for netlify
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVinck committed Jan 29, 2024
1 parent 58c9833 commit 5827c40
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/pages/api/post-reactions/[id].ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ const Postlimiter = rateLimit({
uniqueTokenPerInterval: 500, // Max 500 users per second
});

export const GET: APIRoute = async ({
params,
clientAddress,
}): Promise<Response> => {
export const GET: APIRoute = async ({ params, request }): Promise<Response> => {
const id = params.id;
const userIP = clientAddress;
// This is a Netlify header. Astro has clientAddress but it doesn't work in the Netlify adapter.
const userIP = request.headers.get("client-ip");
console.log("user ip", userIP);

if (!import.meta.env.SECRET_APPWRITE_API_KEY) {
return new Response(JSON.stringify({ error: "internal server error" }), {
Expand Down Expand Up @@ -101,9 +100,10 @@ export const GET: APIRoute = async ({
});
};

export const POST: APIRoute = async ({ request, params, clientAddress }) => {
export const POST: APIRoute = async ({ request, params }) => {
const id = params.id;
const userIP = clientAddress;
// This is a Netlify header. Astro has clientAddress but it doesn't work in the Netlify adapter.
const userIP = request.headers.get("client-ip");

if (!import.meta.env.SECRET_APPWRITE_API_KEY) {
return new Response(JSON.stringify({ error: "internal server error" }), {
Expand Down

0 comments on commit 5827c40

Please sign in to comment.