Can't fetch local sites
Closed this issue · 1 comments
SRCthird commented
I was setting up a server up/down visual and notices all of my non-public servers were erroring out. I set up this super minimal test and still am unable to connect to locally hosted sites.
// My quickly thrown together server
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
const array = ['apple', 'banana', 'cherry'];
res.end(JSON.stringify(array));
});
server.listen(
3000,
'0.0.0.0',
() => {
console.log(`Server running at http://${HOST}:${PORT}/`);
}
);
// js/GetAPI.js
class GetAPI {
GetAPI() { }
async getData() {
try {
const response = await fetch(`http:/localhost:3000`)
return response;
} catch (error) {
return error.message;
}
}
}
<!-- Welcome.md -->
\```dataviewjs
const {GetAPI} = await cJS()
dv.list(await GetAPI.getData())
\```
This should return:
- apple
- banana
- cherry
But actually returns:
- F
- a
- i
- l
- e
- d
... to fetch
SRCthird commented
Nevermind, this was just a CORS issue :P