Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

215
Visualizações
Connection refused error when fetching random images from Unsplash with SvelteKit

I want to make a website for my family company using SvelteKit. My current aim is to get a random nature image from Unsplash and make it the background image of the whole app. I set up the logic and I can get the image to show in the background but I get this error in the browser console, which repeats itself about every second:

GET http://localhost:3000/__vite_ping net::ERR_CONNECTION_REFUSED

Screenshot of the resulting page and console error

Here is index.svelte so far:

<script>
  const accessKey = 'MY_ACCESS_KEY';
  const url = 'https://api.unsplash.com/photos/random?query=nature&client_id=' + accessKey;

  fetch(url)
    .then((res) => {
      if (res.ok) return res.json();
      else alert(res.status);
    })
    .then((data) => {
      console.log(data);
      document.getElementsByTagName('div')[0].style.backgroundImage =
        'url(' + data.urls.regular + ')';
    });
</script>

<title>Küpeli Mühendislik •</title>

<div>
  <h1>Küpeli Mühendislik</h1>
  <p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
</div>

<style>
  @import url('https://fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700&display=swap');
  div {
    font-family: 'Lato', sans-serif;
    width: 95%;
    height: 100vh;
    margin: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    /* background-color: #891f14; */
    color: aliceblue;
  }
</style>

There is also the warning at the top which I don't understand. And also I am guessing the additional background stylings should be added along with the image url and not inside the style tags, since they don't appear to be working.

Any insight would be appreciated. Thanks, Ugur.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you're seeing there is the hot module reloading/dev server for Vite trying to poll over that websocket (http://localhost:3000/__vite_ping), not actually a problem with fetching from unsplash.

I would confirm:

  1. Is the vite dev server running (probably launched with npm run dev)?
  2. Is it running on that port?

Look for the terminal where you started the dev server and look for any errors there as well.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda