Skip to content

hook llms:generate only runs on build time once but not called for every request to /llms.txt? #24

@AronLEEdev

Description

@AronLEEdev

I am trying to implement a server plugin of a nuxt project to change the domain of llms.txt dynamically.
I have set the domain in the nuxt.config.ts to be {DOMAIN} and i intend to replace them using hook llms:generate, here is my code:

// server/plugins/llms.ts
export default defineNitroPlugin(nitroApp => {
	nitroApp.hooks.hook('llms:generate', (event, options) => {
        const host = getRequestHeader(event, 'x-real-host') || getRequestHeader(event, 'x-forwarded-host') || getRequestHeader(event, 'host');
        const proto = getRequestHeader(event, 'x-forwarded-proto') || getRequestHeader(event, 'cloudfront-forwarded-proto') || 'https';
        let fullDomain = ''
        if (host) {
            fullDomain = `${proto}://${host}`;
        }
        console.log('generating llms: fullDomain is ', fullDomain);
        options.sections.forEach(section => {
            const links = section.links;
            links?.forEach(link => {
                link.href = link.href.replace('{DOMAIN}', fullDomain + '/md') + '.md'
            })
        })
        setHeader(event, 'Content-Type', 'text/plain; charset=utf-8');
	});
});
// nuxt.config.ts
llms: {
		// change dynamically afterwards
		domain: '{DOMAIN}',
		title: 'meta-title',
	},

but when i preview it locally after build or deploy on server, neither of them works as expected.
I also notice that the console.log that i have inside the plugin is print out during build process, and a static llms.txt is generated under .output folder.
So my question is according to the docs, this hook should be called on every request:
Image

But this is not as expected as the hook is only called once during build time, or is there something i am doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions