-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
function generateHybridId(request: any) { | ||
// Timestamp: | ||
const timestamp = Date.now(); | ||
|
||
// IP address (if available in request headers): | ||
const ipAddress = | ||
request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip"); | ||
const ipHash = ipAddress ? ipAddress.split(".").slice(0, 2).join("") : ""; // Use first two octets | ||
|
||
// Device ID (using a custom random string generator): | ||
const deviceId = generateRandomDeviceId(); | ||
|
||
return `${timestamp}${ipHash}${deviceId}`; | ||
} | ||
|
||
function generateRandomDeviceId() { | ||
const characters = "abcdef0123456789"; | ||
let result = ""; | ||
for (let i = 0; i < 6; i++) { | ||
result += characters.charAt(Math.floor(Math.random() * characters.length)); | ||
} | ||
return result; | ||
} | ||
|
||
export default function middleware(req: NextRequest) { | ||
// User agent information | ||
// const agent = userAgent(req); | ||
// console.log(agent); | ||
|
||
// Request ID | ||
const requestId = generateHybridId(req); // Use your preferred ID generation method | ||
req.headers.set("x-request-id", requestId); | ||
|
||
return NextResponse.next(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// import { v4 as uuidv4 } from "uuid"; // Import a reliable ID generation library | ||
|
||
// export function generateHybridId() { | ||
// return uuidv4(); // Generate a unique request ID | ||
// } |
9d5beac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
simbio-experimental – ./
simbio-experimental.vercel.app
simbio-experimental-git-main-abuthermuhammad.vercel.app
simbio.enliven.com
simbio.dot9.dev
simbio-experimental-abuthermuhammad.vercel.app