fetch does not work with local urls on Now
See original GitHub issueThe following is the code…
In .src/routes/index.svelte
<script context="module">
export async function preload({ params, query }) {
const res = await this.fetch(`/data`);
const data = await res.json();
return data;//{"title":data.title};
}
</script>
<script>
export let title;
</script>
<h1>Great success! - {title}</h1>
created .src/routes/data.js file and have the following
const superagent = require('superagent');
// GET /data
export function get(req, res, next) {
superagent.get("https://external/api/json/get/path/xyz")
.type("json")
.accept("json")
.query(req.query)
.pipe(res);
}
- {title} in the above code only works when we click on other tabs and back but not when we refresh the index.svelte page
- The same code works fine locally ( localhost ) but not when we deploy to now ( production )
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Fetch request to local file not working - Stack Overflow
Try to place your json file in the public folder like so : public/movies.json. and then fetch using fetch('./movies.json').
Read more >fetch() a local file · Issue #2150 · denoland/deno - GitHub
I'd like to condense the most important reasons I believe URLs of file scheme should not be implemented in node-fetch. I would of...
Read more >Fetch Standard
A URL is local if its scheme is a local scheme. ... mode is assumed to be " include " and fetch does...
Read more >Fetch - The Modern JavaScript Tutorial
JavaScript can send network requests to the server and load new information whenever it's needed. For example, we can use a network request ......
Read more >Fetch API - MDN Web Docs
The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the tips! You can also use
host
property in thepreload
function so you don’t need to hardcode domain URL. This is the workaround I have arrived to:Fix has been released in v0.39.0! Thanks @fpaboim