Skip to content

Commit

Permalink
Merge pull request #215 from os2ulf/feature/canonical-fix
Browse files Browse the repository at this point in the history
Feature/canonical fix
  • Loading branch information
tutaru99 authored Dec 3, 2024
2 parents 892a0ca + 2307ac9 commit 3d2f0cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
15 changes: 5 additions & 10 deletions composables/useGetCurrentDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ export default function useGetCurrentDomain() {

if (process.server) {
const hostHeader = useRequestHeaders();
currentDomain = hostHeader['x-forwarded-host'] || hostHeader.host;

if (
!currentDomain.startsWith('http://') ||
!currentDomain.startsWith('https://')
) {
currentDomain = 'https://' + currentDomain;
}
const rawDomain = hostHeader['x-forwarded-host'] || hostHeader.host || '';
currentDomain = `https://${rawDomain}`;
} else if (process.client) {
currentDomain = window.location.protocol + '//' + window.location.hostname;
const rawDomain = window.location.hostname;
currentDomain = `https://${rawDomain}`;
}

return currentDomain;
}
}
3 changes: 2 additions & 1 deletion utils/seoCanonicalUrlHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const seoCanonicalUrlHandler = (url: string, isFrontPage: boolean) => {
}

const currentDomain = useGetCurrentDomain();
console.log('currentDomain from the composable', currentDomain);
console.log('seoCanonicalUrlHandler from the composable:', currentDomain);


if (isFrontPage) {
return currentDomain;
Expand Down

0 comments on commit 3d2f0cc

Please sign in to comment.