-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adaptor-static no longer generate endpoint like sitemap.xml.ts and robots.txt.ts as a static file #5444
Comments
I'm surprised you saw this behaviour previously — as far as I was aware it never worked automatically, unless you happened to link to the endpoint from a page. #4653 is intended to solve this problem (the PR is somewhat stale, because it depends on other work we haven't found time for yet, but you get the idea), but in the meantime you can work around it with this: prerender: {
default: true,
entries: ['*', '/robots.txt', '/sitemap.xml']
} |
Thanks for your reply there! I have updated my configuration based on that snippets, and I have bumped into another issue, which I am not sure if it is opened somewhere else. I have two routes, It is running fine locally, but when I run it during build, I get the following error from the following code: import fetch from 'node-fetch';
export const get: RequestHandler = async (event) => {
//route for generating sitemap.xml
try {
const res = await fetch(
(dev ? `http://0.0.0.0:${event.url.port}` : event.url.origin) + "/api/metadata"
);
//....
}
so seems like when |
A follow up on the issue, as My suggestion is we allow user to set the default value for |
Ah yeah, that's right. The A potential solution would be to override globalThis.fetch = (url, opts) => {
if (url.startsWith('http://sveltekit-prerender/') {
const request = create_request(url, opts);
return server.respond(request); // calls the endpoint directly
}
return fetch(url, opts);
} Instead of doing this sort of thing to construct the URL... (dev ? `http://0.0.0.0:${event.url.port}` : event.url.origin) + "/api/metadata" ...you'd do this: new URL('/api/metadata', event.url)
I'm not sure I follow this, can you provide a concrete example? |
An example would be building a sitemap for import { SitemapStream, streamToPromise } from "sitemap";
export const get = async (event) => {
try {
const sitemapStream = new SitemapStream({
hostname: event.url.origin, // This will be the domain of the application, detected in the runtime by the serverless function
xmlns: {
image: true,
news: true,
video: true,
xhtml: true
}
});
// Add entries to the sitemap
return {
headers: {
"Content-Type": "application/xml"
},
body: result.toString()
};
} catch (error) {
console.error(error);
return {
status: 500
};
}
}; But the above implementation won't work for
If the value of //svelte.config.js
const config = {
kit: {
prerender: {
default: true,
hostname: 'foo.com' // Possible solution. The value used to replace `sveltekit-prerender`. process.env can be used here as well.
}
}
}
export default config |
…ts during prerendering (#5627) * allow endpoints to make internal fetches during prerendering (#5444) * add config.kit.prerender.origin * changeset * update docs * Update .changeset/weak-parents-compare.md Co-authored-by: Simon H <[email protected]> * Update documentation/docs/15-configuration.md Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Simon H <[email protected]> Co-authored-by: Ben McCann <[email protected]>
Describe the bug
adaptor-static no longer generate endpoint like sitemap.xml.ts and robots.txt.ts as a static file, which it did previously(I don't have an exact version number for that unfortunately. I have seen that behavior roughly 6 months ago?)
Reproduction
https://github.com/winston0410/adaptor-static-repo
Based on the log below, seems like a SSR bundle is generated, even though
adaptor-static
is used. It is generating a SSR bundle.Logs
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: