-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Stop using pages router INTER-911 (#167)
* chore: move remaining page and handler to `app` * chore: clean up files * chore: consolidate layour * chore: more file clean up * chore: fix cors * chore: clean up cors * chore: clean up cors * chore: fix seo * chore: move files around
- Loading branch information
Showing
180 changed files
with
419 additions
and
488 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
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
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,6 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,22 @@ | ||
'use client'; | ||
|
||
import '../client/styles/global-styles.scss'; | ||
import { useSelectedLayoutSegments } from 'next/navigation'; | ||
import { IS_PRODUCTION } from '../envShared'; | ||
import Header from '../client/components/Header/Header'; | ||
import { Analytics } from '../client/analytics/Analytics'; | ||
import Footer from '../client/components/Footer/Footer'; | ||
import styles from './LayoutUI.module.scss'; | ||
|
||
export function LayoutUI({ children }: { children: React.ReactNode }) { | ||
const segments = useSelectedLayoutSegments(); | ||
const embed = Boolean(segments?.includes('embed')); | ||
return ( | ||
<div className={styles.layout}> | ||
{embed ? null : <Header />} | ||
{IS_PRODUCTION ? <Analytics /> : null} | ||
<div>{children}</div> | ||
{embed ? null : <Footer />} | ||
</div> | ||
); | ||
} |
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
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,101 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { EventResponse, isEventError } from '@fingerprintjs/fingerprintjs-pro-server-api'; | ||
import { OUR_ORIGINS } from '../../../../server/checks'; | ||
import { IS_PRODUCTION } from '../../../../envShared'; | ||
import { fingerprintServerApiClient } from '../../../../server/fingerprint-server-api'; | ||
|
||
// Also allow our documentation to use the endpoint | ||
const allowedOrigins = [...OUR_ORIGINS, 'https://dev.fingerprint.com']; | ||
|
||
// Handle CORS | ||
const getCorsHeaders = (origin: string | null) => ({ | ||
'Access-Control-Allow-Origin': String(origin), | ||
'Access-Control-Allow-Methods': 'POST, OPTIONS', | ||
'Access-Control-Allow-Headers': 'Content-Type', | ||
}); | ||
|
||
type CorsHeaders = ReturnType<typeof getCorsHeaders>; | ||
|
||
export async function OPTIONS(request: NextRequest) { | ||
const origin = request.headers.get('origin'); | ||
|
||
// CORS preflight | ||
if (origin && allowedOrigins.includes(origin)) { | ||
return new NextResponse(null, { | ||
status: 200, | ||
headers: getCorsHeaders(origin), | ||
}); | ||
} | ||
|
||
return new NextResponse(null, { status: 204 }); | ||
} | ||
|
||
// Main handler | ||
export async function POST(request: NextRequest, { params }: { params: { requestId: string } }) { | ||
const origin = request.headers.get('origin'); | ||
const requestId = params.requestId; | ||
|
||
// In production, validate the origin | ||
if (IS_PRODUCTION && (!origin || !allowedOrigins.includes(origin))) { | ||
return new NextResponse(null, { | ||
status: 403, | ||
statusText: `Origin "${origin}" is not allowed to call this endpoint`, | ||
headers: getCorsHeaders(origin), | ||
}); | ||
} | ||
|
||
if (!requestId) { | ||
return new NextResponse(null, { | ||
status: 400, | ||
statusText: 'Missing requestId parameter', | ||
headers: getCorsHeaders(origin), | ||
}); | ||
} | ||
|
||
const result = await tryGetFingerprintEvent(requestId); | ||
|
||
if (!result.okay) { | ||
return sendErrorResponse(result.error, getCorsHeaders(origin)); | ||
} | ||
|
||
return NextResponse.json(result.data, { headers: getCorsHeaders(origin) }); | ||
} | ||
|
||
async function tryGetFingerprintEvent( | ||
requestId: string, | ||
retryCount = 5, | ||
retryDelay: number = 3000, | ||
): Promise<{ okay: true; data: EventResponse } | { okay: false; error: unknown }> { | ||
try { | ||
const eventResponse = await fingerprintServerApiClient.getEvent(requestId); | ||
return { okay: true, data: eventResponse }; | ||
} catch (error) { | ||
// Retry only Not Found (404) requests. | ||
if (isEventError(error) && error.statusCode === 404 && retryCount > 1) { | ||
await new Promise((resolve) => setTimeout(resolve, retryDelay)); | ||
return tryGetFingerprintEvent(requestId, retryCount - 1, retryDelay); | ||
} else { | ||
console.error(error); | ||
return { okay: false, error }; | ||
} | ||
} | ||
} | ||
|
||
function sendErrorResponse(error: unknown, corsHeaders: CorsHeaders): NextResponse { | ||
if (isEventError(error)) { | ||
return NextResponse.json( | ||
{ message: error.message, code: error.errorCode }, | ||
{ | ||
status: error.statusCode, | ||
statusText: `${error.errorCode} - ${error.message}`, | ||
headers: corsHeaders, | ||
}, | ||
); | ||
} else { | ||
return new NextResponse(null, { | ||
status: 500, | ||
statusText: `Something went wrong ${error}`, | ||
headers: corsHeaders, | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
File renamed without changes.
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
Oops, something went wrong.