Reputation: 345
I have two .txt files, one of them for example is a list of countries. I need to import the data from these files into a .tsx function that will write them to the merchants theme files as snippets to use.
The issue I have is for some reason these files can't be accessed by my .tsx (even though they're in /public/.
Can someone please share the correct way to access public assets like .txt and .png from a .tsx remix app file? lets assume we're trying to fetch a .txt in app._index.tsx.
Any help here would be appreciated.
Here is my error:
remix │ Error: Failed to parse URL from /countries.txt
Here is the method I'm using to retrieve this file:
const countriesResponse = await fetch("/countries.txt");
Upvotes: 0
Views: 60
Reputation: 86
Try using full url on the request, like:
export async function loader({request}: LoaderFunctionArgs) {
const url = new URL(request.url);
const txt = await (await fetch(`${url}/test.txt`)).text();
console.log('TXT', {txt});
return json({txt});
}
Upvotes: 0