Skip to content
Discussion options

You must be logged in to vote

@davidbourrel I'm using headers to get local information for robots.txt as it's in my root. Both are coming from a CMS's restapi:

async function getPageData() {
    const headersList = headers();
    const host = headersList.get('host') as string;
    const protocol = headersList.get('x-forwarded-proto') || 'http';

    const res = await fetch(`${protocol}://${host}/api/pages/robotstxt`);
    
    if (!res.ok) {
        throw new Error('Failed to fetch page data');
    }
   
    return res.json();
}
  
export default async function robots(): Promise<MetadataRoute.Robots> {
    const headersList = headers();
    const host = (headersList.get('host') || headersList.get('x-forwarded-host')) …

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@amannn
Comment options

Comment options

You must be logged in to vote
2 replies
@davidbourrel
Comment options

@davidbourrel
Comment options

Answer selected by davidbourrel
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants