@@ -113,7 +113,7 @@ export default function EventDetail({ event }: EventDetailProps) {
About This Event
@@ -124,7 +124,7 @@ export default function EventDetail({ event }: EventDetailProps) {
Created:{" "}
- {new Date(event.created_at).toLocaleDateString("en-US", {
+ {new Date(event.createdAt).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
@@ -132,7 +132,7 @@ export default function EventDetail({ event }: EventDetailProps) {
Last Updated:{" "}
- {new Date(event.updated_at).toLocaleDateString("en-US", {
+ {new Date(event.updatedAt).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
diff --git a/src/middleware.ts b/src/middleware.ts
index 6b307ce..8f37347 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -4,6 +4,7 @@ import type { NextRequest } from "next/server";
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
import { StandardResponse } from "./lib/types";
+import { headers } from "next/headers";
const redis = new Redis({
url: process.env.KV_REST_API_URL,
@@ -22,19 +23,24 @@ const resetPasswordRatelimiter = new Ratelimit({
analytics: true,
});
-const ALLOWED_ORIGIN =
- process.env.NODE_ENV === "development"
- ? "http://localhost:3000"
- : "https://re-envision.org";
+const getHostName = async () => {
+ const headersList = await headers();
+ return headersList.get("host");
+};
export async function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
+ const allowedOrigin =
+ process.env.NODE_ENV === "development"
+ ? "http://localhost:3000"
+ : (await getHostName()) || "";
+
if (request.method === "OPTIONS" && pathname.startsWith("/api")) {
return new NextResponse(null, {
status: 204,
headers: {
- "Access-Control-Allow-Origin": ALLOWED_ORIGIN,
+ "Access-Control-Allow-Origin": allowedOrigin,
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
},
@@ -45,6 +51,7 @@ export async function middleware(request: NextRequest) {
const rateLimitResponse = await handleRateLimit(
request,
resetPasswordRatelimiter,
+ allowedOrigin,
);
if (rateLimitResponse) {
@@ -62,13 +69,17 @@ export async function middleware(request: NextRequest) {
status: 500,
headers: {
"Content-Type": "application/json",
- "Access-Control-Allow-Origin": ALLOWED_ORIGIN,
+ "Access-Control-Allow-Origin": allowedOrigin,
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
},
});
} else if (pathname.startsWith("/api")) {
- const rateLimitResponse = await handleRateLimit(request, ratelimit);
+ const rateLimitResponse = await handleRateLimit(
+ request,
+ ratelimit,
+ allowedOrigin,
+ );
if (rateLimitResponse) {
return rateLimitResponse;
@@ -85,7 +96,7 @@ export async function middleware(request: NextRequest) {
status: 500,
headers: {
"Content-Type": "application/json",
- "Access-Control-Allow-Origin": ALLOWED_ORIGIN,
+ "Access-Control-Allow-Origin": allowedOrigin,
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
},
@@ -102,6 +113,7 @@ export const config = {
const handleRateLimit = async (
request: NextRequest,
ratelimiter: Ratelimit,
+ allowedOrigin: string,
): Promise => {
const ip =
request.headers.get("x-real-ip") ??
@@ -119,7 +131,7 @@ const handleRateLimit = async (
status: 429,
headers: {
"Content-Type": "application/json",
- "Access-Control-Allow-Origin": ALLOWED_ORIGIN,
+ "Access-Control-Allow-Origin": allowedOrigin,
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
"Retry-After": reset
@@ -132,7 +144,7 @@ const handleRateLimit = async (
const response = NextResponse.next();
- response.headers.set("Access-Control-Allow-Origin", ALLOWED_ORIGIN);
+ response.headers.set("Access-Control-Allow-Origin", allowedOrigin);
response.headers.set("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
response.headers.set("Access-Control-Allow-Headers", "Content-Type");