Skip to content

Commit

Permalink
Merge pull request #30 from georgeeburt/dev
Browse files Browse the repository at this point in the history
update with new changes
  • Loading branch information
georgeeburt authored Jan 11, 2025
2 parents b9fb628 + 56f63b0 commit 33767ef
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

![Copyright](https://img.shields.io/badge/©-All%20Rights%20Reserved-orange)
[![Vercel Deploy](https://deploy-badge.vercel.app/vercel/reactions-demo)](https://www.burtsoftwaresolutions.dev/)
[![Tests](https://github.com/georgeeburt/portfolio/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/georgeeburt/portfolio/actions/workflows/tests.yml)
[![Tests](https://github.com/georgeeburt/portfolio/actions/workflows/tests.yml/badge.svg)](https://github.com/georgeeburt/portfolio/actions/workflows/tests.yml)
[![Code Style](https://img.shields.io/badge/code%20style-prettier-%23FF69B4?style=flat&labelColor=gray)](https://github.com/prettier/prettier)

<p>This repository contains the source code for my personal portfolio website, showcasing my projects, skills, and experiences as a Full-Stack Developer. Built with Next.js, TypeScript and TailwindCSS, deployed on Vercel.</p>
Expand Down
32 changes: 16 additions & 16 deletions src/app/api/contact/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rateLimiter } from '@/lib/middleware/rate-limiter';
import { NextRequest, NextResponse } from 'next/server';
import { NextRequest } from 'next/server';

export async function POST(request: NextRequest): Promise<Response> {
try {
Expand All @@ -11,26 +11,26 @@ export async function POST(request: NextRequest): Promise<Response> {
const { name, email, message, honeyPot } = await request.json();

if (!name || !email || !message) {
return new NextResponse(
JSON.stringify({
return Response.json(
{
message: 'Name, email, message are all required'
}),
},
{ status: 400 }
);
}

if (honeyPot?.trim()) {
return new NextResponse(
JSON.stringify({
return Response.json(
{
message: 'Spam detected'
}),
},
{ status: 400 }
);
}

if (process.env.NODE_ENV === 'development') {
return new NextResponse(
JSON.stringify({ message: 'Development Mode' }),
return Response.json(
{ message: 'Development Mode' },
{ status: 200 }
);
}
Expand All @@ -54,25 +54,25 @@ export async function POST(request: NextRequest): Promise<Response> {
const data = await res.json();

if (res.ok) {
return new NextResponse(
JSON.stringify({ message: 'Success', data }),
return Response.json(
{ message: 'Success', data },
{
status: 200
}
);
} else {
return new NextResponse(
JSON.stringify({
return Response.json(
{
message: 'Failed to send email',
error: data
}),
},
{ status: res.status }
);
}
} catch (error) {
console.error('Error sending message:', error);
return new NextResponse(
JSON.stringify({ message: 'Error sending message' }),
return Response.json(
{ message: 'Error sending message' },
{
status: 500
}
Expand Down
5 changes: 2 additions & 3 deletions src/app/api/contributions/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { NextResponse } from 'next/server';
import { getContributionsWithCache } from '@/lib/utils/github';

export async function GET() {
try {
const data = await getContributionsWithCache();
return NextResponse.json(data);
return Response.json(data);
} catch (error) {
console.error('Failed to fetch contributions', error);
return NextResponse.json(
return Response.json(
{ error: 'Failed to fetch contributions' },
{ status: 500 }
);
Expand Down
24 changes: 17 additions & 7 deletions src/app/api/cron/route.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { NextResponse } from 'next/server';
import { getContributionsWithCache } from '@/lib/utils/github';
import { NextRequest } from 'next/server';
import { fetchGithubContributions } from '@/lib/utils/github';
import redis from '@/lib/config/redis';

export async function GET(request: Request) {
const CACHE_KEY = 'github:contributions';
const CACHE_TTL = 90000;

export async function GET(request: NextRequest) {
const authHeader = request.headers.get('authorization');

if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return new NextResponse('Unauthorized', { status: 401 });
return Response.json('Unauthorized', { status: 401 });
}

try {
await getContributionsWithCache();
return NextResponse.json({ success: true });
const freshData = await fetchGithubContributions();
await redis.setex(
CACHE_KEY,
CACHE_TTL,
JSON.stringify(freshData)
);

return Response.json({ success: true });
} catch (error) {
console.error('Failed to cache contributions', error);
return NextResponse.json(
return Response.json(
{ error: 'Failed to update contributions cache' },
{ status: 500 }
);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/middleware/rate-limiter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextRequest, NextResponse } from 'next/server';
import { NextRequest } from 'next/server';
import redis from '../config/redis';

const WINDOW_SIZE_IN_SECONDS = 86400;
Expand All @@ -23,7 +23,7 @@ export async function rateLimiter(request: NextRequest) {

const count = parseInt(currentRequestCount);
if (count >= MAX_REQUESTS_PER_WINDOW) {
return NextResponse.json(
return Response.json(
{ message: 'Rate limit exceeded. Please try again later.' },
{
status: 429,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
import redis from '../config/redis';

const CACHE_KEY = 'github:contributions';
const CACHE_TTL = 21600;
const CACHE_TTL = 90000;

export async function fetchGithubContributions() {
const now = new Date();
Expand Down

0 comments on commit 33767ef

Please sign in to comment.