mirror of
https://github.com/Afilmory/afilmory
synced 2026-04-24 23:05:05 +00:00
fix(open-graph): use x-forwarded headers to determine real origin for OG tags
- Updated the Open Graph meta tag generation to utilize x-forwarded headers for determining the real origin, ensuring accurate URLs for og:image and og:url. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -64,12 +64,25 @@ const createAndInsertOpenGraphMeta = (
|
||||
request: NextRequest,
|
||||
) => {
|
||||
// Open Graph meta tags
|
||||
|
||||
// X forward hjost
|
||||
const xForwardedHeaders = {
|
||||
'x-forwarded-host': request.headers.get('x-forwarded-host'),
|
||||
'x-forwarded-proto': request.headers.get('x-forwarded-proto'),
|
||||
'x-forwarded-for': request.headers.get('x-forwarded-for'),
|
||||
}
|
||||
|
||||
let realOrigin = request.nextUrl.origin
|
||||
if (xForwardedHeaders['x-forwarded-host']) {
|
||||
realOrigin = `${xForwardedHeaders['x-forwarded-proto'] || 'https'}://${xForwardedHeaders['x-forwarded-host']}`
|
||||
}
|
||||
|
||||
const ogTags = {
|
||||
'og:type': 'website',
|
||||
'og:title': photo.id,
|
||||
'og:description': photo.description || '',
|
||||
'og:image': `${request.nextUrl.origin}/og/${photo.id}`,
|
||||
'og:url': `${request.nextUrl.origin}/${photo.id}`,
|
||||
'og:image': `${realOrigin}/og/${photo.id}`,
|
||||
'og:url': `${realOrigin}/${photo.id}`,
|
||||
}
|
||||
|
||||
for (const [property, content] of Object.entries(ogTags)) {
|
||||
|
||||
Reference in New Issue
Block a user